Re: syntax-rules problem

Taylor R Campbell <[email protected]>
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <[email protected]>
   Date: Wed, 19 Nov 2008 08:03:00 +0100
   From: Helmut Eller <[email protected]>

   I have some trouble to understand what's wrong with the following macro:

     (begin
       (define-syntax define-a
         (syntax-rules ()
           ((_) (define a 0))))
       (define-a)
       a)

   I would expect that after evaluating (define-a), a is defined
   and that the entire form would return 0. 

   However, Scheme48 (version 1.8) signals an undefined variable error.
   Is this a bug or a feature?

This is the intent of hygiene.  The macro DEFINE-A cannot refer to
names in the user's environment, and the user cannot refer to names in
DEFINE-A's environment.  If you want your macro to define a binding of
a name in the user's environment, the user must supply that name.
SYNTAX-RULES can express only hygienic macros; you will need to use
explicit renaming macros if you want to break hygiene (or concatenate
names, &c.).

Also, by the way, DEFINE-SYNTAX is not valid in local scopes.  While
that program is valid (assuming it occurs in a top-level sequence), if
one were to substitute LET() for BEGIN, it would cease to be valid.
Local macros are written instead with LET-SYNTAX or LETREC-SYNTAX.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.