(def dict
{:key `(str "obj isn't defined in this scope" (:blah ~'obj))})
(defmacro my-macro [obj & args]
`(print ~(:key dict) ~@args))
(macroexpand '(my-macro {:blah "thingy"} "test string"))
I have a need to inline arbitrary code, but that code needs to know about
some things in the context of the macro. In the minimal example, you can
see that I need to get the key :blah from some symbol obj, in this context
one :key might be one set of code, another :key in a list of dicts might
have a completely different bit of code. I want to avoid using functions
here, because despite the simple appearance, calling functions will bee
horrible and messy. Is there any way to accomplish this?
The above example appears to give me what I need, but obj isn't in scope.
I've tried something like the following, but it still isn't correct
(def dict
{:key `(str "obj isn't defined in this scope" (:blah ~'obj))})
(defmacro my-macro [my-obj & args]
`(let [obj my-obj]
(print ~(:key dict) ~@args))
(macroexpand '(my-macro {:blah "thingy"} "test string"))
If it can be done, how. If not, please let me know your thoughts on how to
best accomplish what I need.
--
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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.