[plt-scheme] elementary macro question
On Jun 5, 2006, at 11:28 AM, nusret wrote:
> Hi all,
> I review basics of scheme using Dybvig's book (The
> Scheme Programming Language), and noticed that people
> here discussing macros. On page 60, the author gives
> an incorrect version of *and macro*:
>
> (define-syntax and
> (syntax-rules ()
> ((_) #t)
> ((_ e1 e2 e3 ...)
> (if e1 (and e2 e3 ...) #f))))
>
> Then he goes on to explain why this is wrong. Namely,
> it's claimed in the book that this macro expands as
> follows in the case we call (and (not (= x 0)) (/ 1
> x)):
>
> (if (not (= x 0)) (and (/ 1 x)) #f)
> ....
> etc.
>
> I don't understand how this can happen, as there is no
> pattern taking exactly one parameter: so how can (and
> (/ 1 x)) not trigger an error? Namely, I believe the
> author that this macro is incorrect, but the reason he
> gives... :/ ?? Most probably I am missing something
> very basic and elementary, but...
This is probably a typo, copied from the correct version of `and'. Just
drop the e3 in the pattern and the expansion and re-read the material.
-- Matthias