2010/10/1 Stefan Rohlfing <[email protected]>:
> Dear Clojure Group,
>
> I wanted to expand the 'infix' macro presented in chapter 7.3.1 of
> 'Clojure in Action' to handle nested s-expressions:
>
> My first version did not work:
>
> (defmacro my-infix [expr]
> (if (coll? expr)
> (let [ [left op right] expr]
> (list op (my-infix left) (my-infix right)))
> expr))
>
> ;; Test:
> (my-infix ((3 * 5) - (1 + 1)))
>
> ;; Wrong number of args (1) passed to: user$my-infix
> ;; [Thrown class java.lang.IllegalArgumentException]
Macros a "special" functions meant to be called by the compiler during
macro-expansion. But you a are calling a macro function "directly" in
your function body, instead of generating code that will be expanded
(calling your macro function) by the compiler:
(defmacro my-infix [expr]
(if (coll? expr)
(let [ [left op right] expr]
(list op `(my-infix ~left) `(my-infix ~right)))
expr))
Jürgen
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en