Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:45:29+00:00 2026-06-08T23:45:29+00:00

I have a record (defrecord Rec [id]) I work with it like (def my

  • 0

I have a record (defrecord Rec [id])

I work with it like

(def my ( Rec. 2 ))
(println (:id my))

Now I want to replace record def with macro. So that I could write just

(r 2) 
(println (:id my))

I wrote macro

(defmacro r [id]
   (list 'def 'my (symbol "(") 'Rec. id (symbol ")")))

I checked it with macroexpand

(macroexpand-1 '(r 2))  => (def my ( Rec. 2 ))

But I get RuntimeException: Too many arguments to def on (r 2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:45:33+00:00Added an answer on June 8, 2026 at 11:45 pm

    Creating a symbol out of a left paren is not the same as eval-ing text with a left paren. No special significance is attached to the former; the latter causes the reader to produce a nested list which is then evaluated.

    In other words, Clojure evaluates data structures, not text (or a list of symbols). When you type something in the REPL, that text is read into a data structure, then the data structure is evaluated.

    For this to work correctly, the macro needs to produce a nested list itself:

    (defmacro r [id]
      (list 'def 'my (list 'Rec. id)))
    

    Or better yet, use the syntax quote operator:

    (defmacro r [id]
      `(def my (Rec. ~id)))
    

    For illustrative purposes, you can see what happens when Clojure code is read as text:

    (read-string "(def my (Rec. 2))")
    => (def my (Rec. 2))
    (map type (read-string "(def my (Rec. 2))"))
    => (clojure.lang.Symbol clojure.lang.Symbol clojure.lang.PersistentList)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a record like this: (defrecord User [user-id email]) :but when I
I have a record-set like this that contains unix timestamps to record dates: +----+-----------+-----------+---------+
So basically I have a record that looks like this modulis = record kodas
I have record in table like 'abc 100% text'. I want to search all
I have a record set that includes a date field, and want to determine
I have a record that I write out to a CSV file using FileHelpers.
I have a record that came from the follow linq query: using (var context
I have a record store of items which have (name, quantity, owner, status) Now
I have a master record which I'd like to use with. Here's a very
I have a record of data with unix time date in it i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.