Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this macro in Clojure?

(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)
like image 623
unj2 Avatar asked Dec 10 '25 15:12

unj2


1 Answers

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

like image 191
pmf Avatar answered Dec 12 '25 09:12

pmf