After taking another look through cljs.core I managed to reformulate my macro using js* templates, but am still wondering why the "normal" (and cross-platform) solution doesn't work and also if using the js* way is actually safe in the future (i.e. not just a current implementation detail)?
(defmacro defmathop "Constructs macro to build inlined nested expressions with f applied to inner pairs and f2 to combine results." [name f f2] `(defmacro ~name ([a# b# c#] (list '~'js* (str "((~{} " ~f " ~{}) " ~f2 " ~{})") a# b# c#)) ([a# b# c# d#] (list '~'js* (str "((~{} " ~f " ~{}) " ~f2 " (~{} " ~f " ~{}))") a# b# c# d#)))) (defmathop madd "*" "+") Thanks for any answers! On 23 February 2014 16:28, Karsten Schmidt <i...@toxi.co.uk> wrote: > Btw. My cljs example above is slightly wrong due to my simplifying the email > example. I originally used this ns declaration > > (ns macromath.test > (:require-macros [macromath.core :as m])) > > ...and then of course referred to (m/madd ...) > > But the issue remains regardless... > > On 23 Feb 2014 15:59, "Karsten Schmidt" <i...@toxi.co.uk> wrote: >> >> Hi, I've written a macro to build inline expanded math expressions and >> it's working well in Clojure, however fails with a compile exception >> in CLJS. I'm not sure if this is a shortcoming of the CLJS compiler or >> (much more likely) a mistake with my macro. >> >> (ns macromath.core) >> >> (defmacro defmathop >> "Constructs a macro to build inlined nested expressions with f applied >> to inner pairs and f2 to combine results." >> [name f f2] >> `(defmacro ~name >> ([a# b# c#] `(~~f2 (~~f ~a# ~b#) ~c#)) >> ([a# b# c# d#] `(~~f2 (~~f ~a# ~b#) (~~f ~c# ~d#))))) >> >> (defmathop add + +) >> (defmathop sub - -) >> (defmathop mul * *) >> (defmathop div / /) >> (defmathop madd * +) >> (defmathop msub * -) >> (defmathop addm + *) >> (defmathop subm - *) >> >> lein repl >> >> (use 'macromath.core) >> (madd 2 3 4) >> ; 10 >> (madd 2 3 4 5) >> ; 26 >> >> My short CLJS test is as follows: >> >> (ns macromath.test >> (:use-macros [macromath.core])) >> >> (defn ^:export main >> [] >> (.log js/console (madd 2 3 4 5))) >> >> lein cljsbuild fails with this exception: >> Caused by: java.lang.IllegalArgumentException: No method in multimethod >> 'emit-constant' for dispatch value: class clojure.core$_PLUS_ >> >> How can I rewrite the macro so it properly works with the CLJS compiler? >> Thank you! -- Karsten Schmidt http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.