1
votes

I have been following http://www.gigamonkeys.com/book/ . In the chapter http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html there is a macro called check which has following definition.

(defmacro check (form)
  `(report-result ,form ',form))

From my understanding of macro I though above code is equivalent to following code

(defmacro check (form)
  `(report-result ,form form))

But it throws Comma not inside a backquote..

1

1 Answers

5
votes

If you imagine that form is evaluated to the symbol test, then this is true:

`(report-result ,form ',form))
==> (report-result test 'test)

So the ' is left in the expansion so that in the evaluation the replaced form is quoted. However your "equivalent" does this:

`(report-result ,form form)
==> (report-result test form)

Here you see that form is never replaced so now you need to have a variable named form or else you'll get an error.