Hi again -- First, let me thank all of you for you kind and instructive comments. Kent: thanks for the explanation of the relationships between reader and macro expansion.
Patrick & Meikel: thanks! Your solutions do produce almost what I need; the idea is with (tm a b) I should get back {:a a :b b} Your solutions produce sth equivalent to {:a (eval a) :b (eval b)} in this case. So maybe I am trying sth here that I shouldn't be doing in the first place, but the context of the code is as follows: (defmacro mk-create [creator-name & args] `(defn create [...@args] (let [r# (fetch "records") id# (get-id)] (store "records" (assoc r# id# {:id id# ;; :a a :b b ... obtained from args goes here }))))) So my question is: what is the idiomatic way of getting the desired result? Thanks again, I really appreciate all your responses. Best regards, Ingolf On Sep 5, 2:18 pm, Kent <squi...@aol.com> wrote: > When clojure evaluates a piece of code it goes through several steps. > First the reader takes the string representation of your code and > turns it into the clojure data structures represented by your code. > Those data structures are then sent to the compiler for compilation, > including possible macro expansion. > > Your code contains {~@(mapcat (fn [x] (list (keyword x) x)) args)} in > it. The {} characters instruct the reader that this is a literal > map. The reader expects a literal map to have an even number of > elements, which your code does not have. It has one element. > Therefore the reader throws an out of bounds exception. The exception > is being thrown by the reader (the bit that takes a string and turns > it into clojure datastructures) BEFORE it ever gets to the point where > it is trying to do a macro expansion. > > Note that {:a} by itself also throws an ArrayIndexOutOfBounds > exception. > > K. -- 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