How to capture in the lexical area in a Clojure macro?

In Common Lisp, I can define and use a macro that captures a variable from the lexical domain, so I can use it in the let form:

 CL-USER> (defmacro plus9 () `(+ 9 woo)) PLUS9 CL-USER> (macroexpand '(plus9)) (+ 9 WOO) T CL-USER> (let ((woo 1)) (plus9)) 10 

However, when I define a similar macro in Clojure, it searches for the definition of woo in the user namespace:

 user=> (defmacro plus9 [] `(+ 9 woo)) #'user/plus9 user=> (macroexpand '(plus9)) (clojure.core/+ 9 user/woo) user=> (let [woo 1] (plus9)) CompilerException java.lang.RuntimeException: No such var: user/woo 

Clearly, I don’t understand how areas work in Clojure. What is the correct way to achieve this macro with Clojure?

+6
source share
1 answer

I'm a noob macro, but what about

 user=> (defmacro plus9 [] `(+ 9 ~'woo)) #'user/plus9 user=> (macroexpand '(plus9)) (clojure.core/+ 9 woo) user=> (let [woo 1] (plus9)) 10 
+8
source

All Articles