Hi,

Am 07.02.2009 um 22:19 schrieb samppi:

(defmacro bar [factor arg]
 `(foo ~@(replicate factor arg)))

...but then when I use it I get a ClassCastException if I try to do
something like (bar (dec 5) something), because then Clojure tries to
evaluate (replicate '(dec 5) 'something).

So how should I rewrite bar to behave like bar-fn, then?

The point is: you can't! Macros cannot depend on runtime
information. And the value function call (dec 5) is runtime
information.

There is an apply macro in clojure.contrib:
http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/apply_macro.clj

The warnings in there are there for a reason.

For more information simply search the google group
for apply and macro. This should give plenty of other
information concerning this issue.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to