unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Marco Maggi <marco.maggi-ipsu@poste.it>
Cc: bug-guile@gnu.org
Subject: Re: [r6rs] probably bad syntax expansion
Date: Sun, 08 Aug 2010 12:41:06 +0200	[thread overview]
Message-ID: <m38w4h1j5p.fsf@unquote.localdomain> (raw)
In-Reply-To: <m3hbkwb351.fsf@pobox.com> (Andy Wingo's message of "Mon, 21 Jun 2010 21:24:10 +0200")

Hello,

On Mon 21 Jun 2010 21:24, Andy Wingo <wingo@pobox.com> writes:

> On Mon 21 Jun 2010 09:59, Marco Maggi <marco.maggi-ipsu@poste.it> writes:
>
>> (define A <function-using-macro-B>)
>> (define-syntax B <>)
>> (A)
>
> I have abbreviated your illuminating example. I don't really know what
> to think of it, except to say that for top-level programs Guile
> implements "REPL semantics".

This is not quite the right explanation of the situation. Here is what I
have put in the section "R6RS incompatibilities" in the manual.

  Instead of using the algorithm detailed in chapter 10 of the R6RS,
  expansion of toplevel forms happens sequentially.

  For example, while the expansion of the following set of recursive
  nested definitions does do the correct thing:

  @example
  (let ()
    (define even?
      (lambda (x)
        (or (= x 0) (odd? (- x 1)))))
    (define-syntax odd?
      (syntax-rules ()
        ((odd? x) (not (even? x)))))
    (even? 10))
  @result{} #t
  @end example

  @noindent
  The same definitions at the toplevel do not:

  @example
  (begin
   (define even?
     (lambda (x)
       (or (= x 0) (odd? (- x 1)))))
   (define-syntax odd?
     (syntax-rules ()
       ((odd? x) (not (even? x)))))
   (even? 10))
  <unnamed port>:4:18: In procedure even?:
  <unnamed port>:4:18: Wrong type to apply: #<syntax-transformer odd?>
  @end example

  This is because when expanding the right-hand-side of @code{even?}, the
  reference to @code{odd?} is not yet marked as a syntax transformer, so
  it is assumed to be a function.

  While it is likely that we can fix the case of toplevel forms nested in
  a @code{begin} or a @code{library} form, a fix for toplevel programs
  seems trickier to implement in a backward-compatible way. Suggestions
  and/or patches would be appreciated.

Admittedly, it seems silly to document incompatibilities instead of
fixing them :P

Andy
-- 
http://wingolog.org/



      reply	other threads:[~2010-08-08 10:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-21  7:59 [r6rs] probably bad syntax expansion Marco Maggi
2010-06-21  8:02 ` Marco Maggi
2010-06-21  8:34   ` Marco Maggi
2010-06-21 19:24 ` Andy Wingo
2010-08-08 10:41   ` Andy Wingo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m38w4h1j5p.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=bug-guile@gnu.org \
    --cc=marco.maggi-ipsu@poste.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).