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 7511193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:28:21+00:00 2026-05-29T23:28:21+00:00

In clojure , apply cannot be applied to a macro. For instance (apply and

  • 0

In clojure, apply cannot be applied to a macro. For instance (apply and [true false]) raises an exception. I was thinking about following workaround:

(defmacro apply-macro[func args] `(~func ~@args))

At first glance, it seemed to work pretty well:

(apply-macro and [true 5]); 5
(apply-macro and [true 5 0]); 0
(let [a 0] (apply-macro and [true a])); 0

But, when I passed to it a variable that points to a vector, it collapsed.

(let [a [true]] (apply-macro and a));  java.lang.IllegalArgumentException:
   ;Don't know how to create ISeq from: clojure.lang.Symbol

What a disappointment!!!!

Any idea how to fix apply-macro?

  • 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-29T23:28:22+00:00Added an answer on May 29, 2026 at 11:28 pm

    The problem is that a is just a symbol at compile time. So there’s no way for a compile-time macro to see what it contains and do the necessary expansion. As a result, you need to expand the macro at run-time using eval.

    One way to do this is just to wrap the macro in a function that calls eval, which can be done with this handy “functionize” macro:

    (defmacro functionize [macro]
      `(fn [& args#] (eval (cons '~macro args#))))
    
    (let [a [true]] (apply (functionize and) a))
    => true
    

    If you like, you could also define apply-macro in terms of functionize:

    (defmacro apply-macro [macro args]
       `(apply (functionize ~macro) ~args))
    
    (let [a [true false]] (apply-macro and a))
    => false
    

    Having said all this, I still think the best thing to do is to avoid macros entirely when they are not really needed: they add extra complexity and are best reserved for cases when you really need compile time code generation. In this case you don’t: Alex Taggart’s answer gives a good example of how to achieve a similar objective without any macros, which is probably more appropriate in most situations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the first strange thing about map in clojure is in following snippet: (apply map
If I do the following: user=> (-> [1 2] (partial apply str)) #<core$partial__5034$fn__5040 clojure.core$partial__5034$fn__5040@d4dd758>
I'm not very familiar with Clojure/Lisp macros. I would like to write apply-recur macro
I have the following Clojure code and I'm not sure why it's not working:
I was reading about Clojure and found a discussion about Java not supporting tail
I cannot use logical functions on a range of booleans in Clojure (1.2). Neither
(Clojure newbie) On my linux machine, slurping /proc/cpuinfo raises an error: user=> (slurp /proc/cpuinfo)
I'm trying (as a self-learning exercise) to create a Clojure macro that will generate
I am working on a Clojure macro to help build GridBagLayout-based JPanels. I can
Clojure macro noob here. I have a function with some optional parameters, e.g. (defn

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.