On Tue, May 12, 2009 at 11:22 AM, samppi <rbysam...@gmail.com> wrote:
>
> Oh, no...I understand now—it looks like I've incorrectly explained my
> problem.
>
> I want to use the macro like this: (a 1 2 3) equivalent to (m-seq [1 2
> 3]).
>
> Clojure 1.0.0-
> user=> (use 'clojure.contrib.monads)
> nil
> user=> (defn a [& xs]
> (with-monad maybe-m (m-seq xs)))
> #'user/a
> user=> (a 1 2 3)
> (1 2 3)
> user=> (defmacro b [& xs]
> `(with-monad maybe-m (m-seq ~xs)))
> #'user/b

I haven't played with monads at all, but if I'm understanding
everything correctly, I believe macroexpand is your friend again,
here:

1:8 user=> (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, the arguments are put into a list with this version and "1" is
being called as a function. However, with this you get your vector:

1:9 user=> (defmacro c [& xs] `(with-monad maybe-m (m-seq ~(apply vector xs))))
#'user/c
1:10 user=> (c 1 2 3)
(1 2 3)
1:11 user=> (macroexpand-1 '(c 1 2 3))
(clojure.contrib.monads/with-monad clojure.contrib.monads/maybe-m
(clojure.contrib.monads/m-seq [1 2 3]))

HTH,

- J.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to