On Mon, Aug 3, 2009 at 8:01 PM, CuppoJava <patrickli_2...@hotmail.com>wrote:

>
> You can use eval to retrieve the value of a-map when the macro is
> expanded.
>
> (let [value (eval a-map)]
>  `(binding ~(vec (process-a-map value)) ~...@forms))
>
> I've programmed some substantial programs now in Clojure though, and
> I've never had to use this. Perhaps there is another way to achieve
> what you want?
>
> As a rule of thumb that I use, using a macro should only look like a
> syntax extension. There shouldn't be any dependance on the values of
> any of the arguments.


Eh, I hadn't noticed that; he's using process-a-map already in a ~
expression. That's the sort of thing more usually done in a helper function:

(defn binding-from-map [a-map forms]
  `(binding ~(vec (process-a-map a-map)) ~...@forms)))

Then call from a macro:

(defmacro foo [map & body]
  (binding-from-map map body))

(foo {:a 1} (fn1 arg1) (fn2 arg2 arg3))

If you really want to call the eventual macro with a non-literal map,
though, then you'll need it to eval that argument as Patrick says.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to