@Phlex & @MikeM, apologies I checked back on Chouser's post and it helped me
to understand that Clojure takes a different approach to macros than Common
Lisp:
Common Lisp
-
(defmacro foobar ()
`(+ a b))
(let
((a 5)
(b 6))
(foobar))
Clojure
@Phlex, I understand why the code is usually bad form.
@MikeM, I had already noticed that it worked on the REPL when I defined
vars. My questions was _why_ it does not work in the case where I have
locals via a let expression?
David
On Mon, Nov 3, 2008 at 12:27 PM, MikeM <[EMAIL PROTECTED]>wrote
On Nov 3, 9:57 am, David Nolen <[EMAIL PROTECTED]> wrote:
> (defmacro foobar []
> `'(+ a b))
>
> (let
> [a 5
> b 6]
> (eval (foobar)))
>
> I know that the above is completely useless but I'm just trying to get
> an intuitive understanding of how macros work under Clojure. At the
>
David Nolen wrote:
> (defmacro foobar []
> `'(+ a b))
>
> (let
> [a 5
> b 6]
> (eval (foobar)))
>
>
>
-You should almost never have to use eval.
-Don't use macros when a function will do
Thanks to the answer of chooser a bit earlier :
cara.trie> (defmacro foobar [] `(+ ~'a ~'b)
(defmacro foobar []
`'(+ a b))
(let
[a 5
b 6]
(eval (foobar)))
I know that the above is completely useless but I'm just trying to get
an intuitive understanding of how macros work under Clojure. At the
REPL when I try to evaluate the second form, I get an null pointer
exception. W