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

  • Home
  • SEARCH
  • 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 4074984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:14:25+00:00 2026-05-20T17:14:25+00:00

This is not my ‘production code’ but a simplication of the problem for illustration

  • 0

This is not my ‘production code’ but a simplication of the problem for illustration purposes. Also, the title of this question is misleading because it brings to mind the ~@ expansion, which I understand, and which may not necessarily be the problem. Please suggest a better question title if you can.

Given a macro with the following form:

(defmacro my-add [x & ys] `(+ ~x ~@ys))

Now let’s say we have a list:

(def my-lst '(2 3))

Now I want a function that uses my-add that I can pass my-lst to as an arg, i.e.

(call-my-add 1 my-lst)

I define the function in what would seem to be the obvious way:

(defn call-my-add [x ys]
    (apply my-add (cons x ys)))

But:

java.lang.Exception: Can't take value of a macro: #'user/call-my-add (repl-1:60)

I’ve tried all sorts of wild tricks to get the call-my-add function to work using evals, applies, and even defining call-my-add as a macro, but they all give similar ClassCastExceptions.

Is there any way out of this?

  • 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-05-20T17:14:26+00:00Added an answer on May 20, 2026 at 5:14 pm

    No. Macros do not, cannot, will never, have access to the actual run-time values contained in their arguments, so cannot splice them into the expansion. All they get is the symbol(s) you pass to them, in this case my-list. The “way around this” is to define my-add as a function, and then (optionally) have a macro that calls that function in order to generate its code.

    I wrote a blog post about this semi-recently that you might find enlightening.

    You could do it with evals if you wanted to, but that is a terrible idea in almost every case:

    (let [my-list '(1 2)]
      (eval `(my-add 5 ~@my-list)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this not being a real question, but Sometime back i remember seeing
This is not exactly a programming question, but it's highly related. We are writing
This is not a technical problem, but very annoying. Does anyone know how to
This is not a really technical question but is required for a system I
This is not a new topic, but I am curious how everyone is handling
This may not be the correct way to use controllers, but I did notice
This is not yet particularly programing related but, I am very interested in how
Why does this code not work? echo explode(?, $_SERVER[REQUEST_URI])[0]; It says syntax error, unexpected
Why is this not working ? StreamReader m = new StreamReader(../folder1/email.html, System.Text.Encoding.UTF8); code file
I want exactly like this...not a simple box but the one with shadow borders

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.