Hi,
On Aug 3, 11:43 pm, samppi <[email protected]> wrote:
> (def my-map {:a 2})
> (defn process-a-map [arg] ...)
> ; Turns maps into corresponding vectors.
> ; (process-a-map my-map) returns ['*foo* :blah].
>
> (my-macro a-map ; Last statement
> (do-something))
The answer which should leave the least grey hair is:
this is not possible. While it is true, that you can use
`eval` to get the map as the others pointed out, you
don't want to do that. Suppose you had my-macro with
`eval`.
(let [my-map {:a 2}]
(my-macro my-map (do-something)))
(defn my-fancy-fn
[the-map-as-arg]
(my-macro the-map-as-arg (do-something)))
Neither of these two forms work and this is a serious
limitation because you are tied to global variables....
> (binding [*foo* :blah] (do-something))
For this special case however you can solve the issue
as follows:
(defn my-macro*
[the-map thunk]
(clojure.lang.Var/pushThreadBindings the-map)
(try
(thunk)
(finally
(clojure.lang.Var/popThreadBindings))))
(defmacro my-macro
[the-map & body]
`(my-macro* ~the-map (fn [] ~...@body)))
Hope this helps.
Sincerely
Meikel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---