We now have the declare macro in Clojure: (defmacro declare "defs the supplied var names with no bindings, useful for making forward declarations." [& names] `(do ~@(map #(list 'def %) names)))
That's structurally similar to a macro I'm having trouble getting right. Here's a modification of declare that shows the problem I'd appreciate help with: (defmacro declare-init [vecs] `(do ~@(map #(list 'def (first %) (second %)) vecs))) This takes a seq of seqs where each inner seq is a pair of a variable name and an init value. It works with a literal for vecs: user=> (declare-init [[a 1] [b 2] [c 3]]) #=(var user/c) But if I def the seq of seqs: user=> (def myvecs '[[a 1] [b 2] [c 3]]) #=(var user/myvecs) user=> myvecs [[a 1] [b 2] [c 3]] declare-init doesn't work with it: user=> (declare-init myvecs) java.lang.IllegalArgumentException: Don't know how to create ISeq from: myvecs (Symbol) (NO_SOURCE_FILE:17) [please see footnote] I tried to tweak the macro to get the vecs argument evaluated (unquoting vecs on the right): user=> (defmacro declare-init [vecs] `(do ~@(map #(list 'def (first %) (second %)) ~vecs))) but that's not legal: java.lang.RuntimeException: Can't embed unreadable object in code: #<[EMAIL PROTECTED]> (NO_SOURCE_FILE:18) How can one write declare-init so that this works: user=> myvecs [[a 1] [b 2] [c 3]] user=> (declare-init myvecs) and has the same effect as: user=> (declare-init [[a 1] [b 2] [c 3]]) #=(var user/c) --Steve [footnote] this is an error message I enhanced to give the name (myvecs) as well as the class (Symbol) because it can be pretty hard to determine what the message is talking about from the current Clojure error message which just says "Symbol". I'd appreciate seeing this enhancement made to Clojure as part of the ongoing error message clarity initiative. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---