Thanks! That got me back on track. I'm off and running on my DSL: (defmacro sketch [title & code] (let [code-map (assemble-map #{:setup :draw} :draw code) setup-slice (:setup code-map) draw-slice (:draw code-map)] `(let [setup-fn# (to-fn ~setup-slice) draw-fn# (to-fn ~draw-slice)] (run-sketch ~title setup-fn# draw-fn#))))
It's a bit challenging at first; I was very concerned with symbol name collisions ... it takes a bit to realize that symbols you use in a macro body (that are not part of the back quoted template) can't conflict with symbols in forms passed to the macro; by the time those passed forms are ever evaluated, the (let) in the macro is long gone and the namespaces are clean. On Tue, Mar 10, 2009 at 12:30 PM, Chouser <chou...@gmail.com> wrote: > > On Tue, Mar 10, 2009 at 2:45 PM, Howard Lewis Ship <hls...@gmail.com> wrote: >> >> (defmacro example >> [& code] >> `(let [rcode# ~(reverse code) >> fn# (to-fn rcode#)] >> (run-example fn#))) > > Thanks for the complete example, it really helps. > > Macroexpand might help you see at least one of the problems: > > (clojure.core/let [rcode__614__auto__ ((printf "EXAMPLE2\n") (printf > "EXAMPLE1\n")) > fn__615__auto__ (user/to-fn rcode__614__auto__)] > (user/run-example fn__615__auto__)) > > Since (printf ...) returns nil, it looks like you'll be trying to bind > rcode# to the value of (nil nil), that is 'nil' called with a single > argument of 'nil'. It actually errors out before it gets that far, > but anyway... > > Try completing as much of your manipulation as is possible outside the > syntax-quote: > > (defmacro example [& code] > (let [rcode (reverse code)] > `(let [func# (to-fn ~rcode)] > (run-example func#)))) > > Also, try to avoid using builtin names like 'fn' for your own locals. > It only leads to more pain in the long run. > > --Chouser > > > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --~--~---------~--~----~------------~-------~--~----~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---