On Apr 30, 2009, at 17:39, samppi wrote:
> I'm having trouble trying to create a macro that calls domonad with
> one argument already filled in: (domonad parser-m rest-of-arguments).
> parser-m is a monad defined in the same namespace. This is what I have
> right now:
> (defmacro complex
> [steps & product-expr]
> `(domonad ~parser-m ~steps ~product-expr))
Unquote (the tilde) is used to insert the value of an expression into
a template. That is fine for ~steps and ~product-expr. But ~parser-m
would insert the *value* of parser-m, not the name itself. Try this
instead:
(defmacro complex
[steps & product-expr]
`(domonad parser-m ~steps ~product-expr))
Another variant is:
(defmacro complex
[steps & product-expr]
`(domonad ~'parser-m ~steps ~product-expr))
The subtle difference is that ~'parser-m will insert an unqualified
symbol into the template, whereas just parser-m will get you a
namespace-qualified symbol that results of a namespace lookup of
parser-m. In this particular case, you can use either, because the
unqualified symbol you get from ~'parser-m will be expanded to a
namespace-qualified symbol when the domonad macro is expanded.
Konrad.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---