justinethier/husk-scheme — Issue #65: Pitfall 3.2 - Buggy use of begin in r5rs cond and case macros
Author: justinethier
Created: 2011-12-17 03:25:02+00:00
State: open

The following example from http://groups.google.com/groups?selm=87bse3bznr.fsf%40radish.petrofsky.org illustrates an important property of R5RS macros:

(should-be 3.2 2
(let-syntax ((foo (syntax-rules ()
((_ var) (define var 1)))))
(let ((x 2))
(begin (define foo +))
(cond (else (foo x)))
x)))

See also http://okmij.org/ftp/Scheme/macros.html#syntax-rule-dark-corner
In particular:

> It appears what matters is not how a Scheme system treats top-level defines but how a macro-expander thinks the underlying system treats top-level defines.