Hi there, On 29 Jul 2011, at 10:05, Alan Malloy wrote: > > (defn binding-vec [foos] > ['size `(count ~foos)]) > > (defmacro magic-fn > [& forms] > (let [args (gensym 'args)] > `(fn [& ~args] > (let ~(binding-vec args) > ~@forms)))) > > ((magic-fn (+ size 10)) 1 2) ;=> 12
Actually, sadly, this still quite doesn't do what I want - and definitely highlights the perils of over-simplifying the question! I'd like binding-vec to generate the binding vector entirely from foos, i.e. both the binding name and value. Imagine that there's a var names: (def names ['size 'foo 'bar 'baz]) To continue in the context of the (over-simplified) question, I'd like binding-vec to dynamically generate me a vec of: ['size `(count ~foos) 'foo `(count ~foos) 'bar `(count ~foos) 'baz `(count ~foos)] However, something like the following doesn't work: (defn binding-vec [foos] `(vec (interleave ~names ~(take (count names) (repeat '`(count ~foos)))))) A, because the above code is probably incorrect (I just cobbled it together for the example) and more importantly: B, because the code doesn't return a vec, it returns code that returns a vec. I really seem to be getting my brain in a knot over this. :-( Any illumination would be really appreciated Sam --- http://sam.aaron.name -- 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