I see—thank you very much. But I suppose I don't understand how vector expressions work in macros. I thought that using ~@ would get me an argument error.
I thought that: `(with-monad maybe-m (m-seq ~xs))) would insert [1 2 3] where ~xs would be, becoming the list: (with-monad maybe-m (m-seq [1 2 3])) Apparently, the xs I was inserting was the list ([1 2 3]). But why is this? If I called (b (vector 1 2 3)) shouldn't it insert it like this? (with-monad maybe-m (m-seq (vector 1 2 3))) Why is xs ([1 2 3]) when I call the original macro (b [1 2 3])? On May 11, 11:18 pm, Konrad Hinsen <konrad.hin...@laposte.net> wrote: > On 11.05.2009, at 23:17, samppi wrote: > > > user=> (defmacro b [& xs] > > `(with-monad maybe-m (m-seq ~xs))) > > #'user/b > > user=> (b [1 2 3]) > > java.lang.IllegalArgumentException: Wrong number of args passed to: > > LazilyPersistentVector (NO_SOURCE_FILE:0) > > > So there's something wrong with how I'm phrasing the macro. But I > > can't figure out what's going on. > > The best way to find out is macroexpand-1: > > (macroexpand-1 '(b [1 2 3])) > -> (clojure.contrib.monads/with-monad clojure.contrib.monads/maybe-m > (clojure.contrib.monads/m-seq ([1 2 3]))) > > So what you are feeding to m-seq is a list containing a vector. The > solution is: > > (defmacro b [xs] > `(with-monad maybe-m (m-seq ~xs))) > (b [1 2 3]) > -> (1 2 3) > > Or, if you prefer: > > (defmacro b [& xs] > `(with-monad maybe-m (m-seq ~...@xs))) > > Konrad. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---