[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Internal defines
From: |
Dirk Herrmann |
Subject: |
Internal defines |
Date: |
Sun, 09 Nov 2003 23:40:26 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 |
Hi folks,
Guile currently chokes on the following form:
(defmacro a forms
(cons 'define forms))
(let ((c identity) (x #t))
(define (a x y) (and x y))
(a (c x) (c x))))
According to R5RS, the body of a form like lambda, let, let* etc. looks
like follows:
<body> --> <definition>* <sequence>
<sequence> --> <command>* <expression>
<command> --> <expression>
<definition> --> (define <variable> <expression>)
| (define (<variable> <def formals>) <body>)
| (begin <definition>*)
That is, it starts with zero or more definitions followed by one or more
expressions.
The definition forms must start with the literal symbol 'define' or
'begin', which
may enclose further definitions or begin forms. In any case, there is
no mentioning
of macro expansion here.
In other words, the examle code above should return #t, because the
expression
(a (c x) (c x)) refers to the internal define rather than to the outer
macro.
Guile, however, has up to now performed macro expansion before checking
whether the
form is a definition. Thus, the example above returns an error, since Guile
interprets (a (c x) (c x)) as a macro application, in this case a
definition.
The body then (according to Guile's interpretation) consists only of
definitions.
The above example also shows that it is no good practice to define
macros that
expand into definitions. Messing with 'define' always means to play
around with
one of scheme's most basic syntactical structures. The optargs
implementation
of define* is an example for a macro that expands to a 'define' form.
According
to R5RS and as demonstrated by the above example, such macros are
confusing, and
Guile's current implementation breaks code that already has a meaning
with respect
to R5RS.
I am about to submit a patch that fixes Guile's behaviour, such that the
example
above would work. This means, that there is not macro expansion
performed prior
to detecting the internal defines. I want, however, to check with you
before doing
so, since it is likely to break existing code. In the long term, just
to mention
it early, I would also like to fix Guile's code such that it also
handles top-level
defines correctly, since there a similar problem applies.
Best regards
Dirk Herrmann
- Internal defines,
Dirk Herrmann <=