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?
source share