For reference, the deriv macro is at http://github.com/liebke/incanter/blob/master/modules/incanter-core/src/incanter/symbolic.clj
Unquote splicing and switching to `(fn ~fn-args ~(deriv exp v degree)) both produce errors of the type "count not supported on this type: Symbol". Macroexpand-1 seems to just return what was fed into it, ie user=> (macroexpand-1 '(deriv-fn [x y] (+ (* x y) (* 3 y)) y 1)) (deriv-fn [x y] (+ (* x y) (* 3 y)) y 1)) Which is also somewhat confusing to me, because I know that there genuinely is a function being declared (ie (fn? f) = true, and it throws an error with an improper number of arguments). I don't know if I was being clear that the problem seems to be that the output of deriv-fn is (fn [x y] '(+ x 3)) rather than (fn [x y] (+ x 3)) Macros definitely do make my head hurt :) On May 4, 4:24 pm, Jarkko Oranen <chous...@gmail.com> wrote: > On May 4, 10:40 pm, Bryce <fiat.mo...@gmail.com> wrote: > > > > > I have a macro, deriv, that produces an expression, and I'd like to > > create another macro that turns this into a function. So far I have > > > (defmacro deriv-fn [fn-args exp v degree] > > `(fn ~fn-args (deriv ~exp ~v ~degree))) > > > Which of course doesn't work, since it considers the output of deriv > > as a quoted list. So for instance > > > (def f (deriv-fn [x y] (+ (* x y) (* 3 y)) y 1)) > > > results in a function f of two variables which always returns '(+ x > > 3) , rather than a function which evaluates (+ x 3). > > > I feel like this is a nested backquote thing, where I could get it to > > resolve at the correct point through artful use of ` and ~~, but I've > > not been able to figure it out - am I on the right track? > > If deriv is a function that returns an expression, you need to do > (defmacro deriv-fn [args exp v degree] > `(fn ~args ~(deriv exp v degree))) > > -- > 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 > athttp://groups.google.com/group/clojure?hl=en -- 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