Thanks Meikel,

your negative answer actually helped me analyze my problem better and
get the distinction run time / expansion time straight. I figured that
the names of the bindings are already there at expansion time and it's
only the values that I need to retrieve at run time.

So this version

(defmacro let-coll
  [ks val-fn & body]
    `(let ~(vec (mapcat #(list % `(~val-fn '~%)) ks)) ~...@body))

allows me to do this:

user=> (def m {'a 1 'b 2 'c 3})
#'user/m

user=> (let-coll (a b c) m (list a b c))
(1 2 3)

And although the macro itself looks a bit ugly (suggestions on
improvement welcome!), it expands very cleanly:

user=> (macroexpand-1 '(let-coll (a b c) m (list a b c)))
(clojure.core/let [a (m (quote a)) b (m (quote b)) c (m (quote c))]
(list a b c))

This macro is of course not very useful, it is - for the sake of
simplicity - a stripped-down version of something more sophisticated.
But if it was the real macro, I guess I should have forced the
parameter "ks" to be vector, to make it more look like let, or fn.

Thanks again for all the answers, also the ones from John, which I
might need in the future, but I'm glad I could get away with a single
(more or less) simple macro this time :)
--~--~---------~--~----~------------~-------~--~----~
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