On Fri, Jul 17, 2009 at 11:52 PM, Rowdy Rednose <rowdy.redn...@gmx.net>wrote:

>
> How can I lexically bind names like "let" does in a macro, when names
> and values for those bindings are passed in?
>
> This here works fine when I pass a literal collection:
>
> (defmacro let-coll
>  [coll & body]
>  `(let ~(vec coll) ~...@body))
>
> user=> (let-coll [a 11 b 22] (list b a))
> (22 11)
>
> Doing the same with a var doesn't work though:
>
> user=> (def x ['a 11 'b 22])
> #'user/x
> user=> (let-coll x (list b a))
> java.lang.Exception: Unable to convert: class clojure.lang.Symbol to
> Object[] (NO_SOURCE_FILE:0)
>
> Any ideas?
>

It'll be evaluating (vec 'x) during macro expansion, which gives that error.
The argument x has to be evaluated for it to work, so you'd need (vec (eval
x)) in there. Then you'll also need to quote when passing in a literal
vector, e.g. (let-coll ['a 11 'b 12] (list b a)).

--~--~---------~--~----~------------~-------~--~----~
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