unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Internal defines
@ 2003-11-09 22:40 Dirk Herrmann
  2003-11-11  2:21 ` Rob Browning
  0 siblings, 1 reply; 6+ messages in thread
From: Dirk Herrmann @ 2003-11-09 22:40 UTC (permalink / raw)


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




_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-11-11  4:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-09 22:40 Internal defines Dirk Herrmann
2003-11-11  2:21 ` Rob Browning
2003-11-11  3:11   ` Tom Lord
2003-11-11  3:50     ` David Van Horn
2003-11-11  4:22       ` Tom Lord
2003-11-11  4:33       ` Tom Lord

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).