views:

92

answers:

2
(defmacro nif [expr pos zer neg]
  '(condp = (Integer/signum ~expr) 
     -1 ~neg
     0 ~zer
     1 ~pos))

I get this error.

1:1 user=> #<Namespace Chapter7Macros>
1:2 Chapter7Macros=> (nif 1 (+ 2 2) (- 2 2) (- 3 2))
1:3 Chapter7Macros=> java.lang.Exception: Unable to resolve symbol: expr in this context (repl-1:57)
+4  A: 

Replace the quote (') by a backtick (`) to enable syntax-quoting.

pmf
+2  A: 

In general using (macroexpand-1 '(nif 1 ... )) will help a lot by showing you the code your macro is actually translating into.

Arthur Ulfeldt
Thanks.
kunjaan