unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Dirk Herrmann <dirk@ida.ing.tu-bs.de>
Cc: Marius Vollmer <mvo@zagadka.ping.de>,
	Guile Development List <guile-devel@gnu.org>
Subject: Re: Syntax checks
Date: Sat, 13 Apr 2002 11:01:26 +0200 (MEST)	[thread overview]
Message-ID: <Pine.LNX.4.21.0204131032500.22358-100000@marvin.ida.ing.tu-bs.de> (raw)
In-Reply-To: <02040915485508.29769@locke.free-expression.org>

On Tue, 9 Apr 2002, Lynn Winebarger wrote:

>          The real question (lingering from at least late 2000) seems to be
> whether lambda abstractions should delay expansion as well as evaluation.
> My first impulse is to say it shouldn't, that macros are "evaluated" at read 
> time.  Among other effects of using lambda to delay expansion, you have
> introduced a definite evaluation ordering of applications.  I'm guessing one
> of the appeals of this behaviour is that in
> (define (foo x) (bar x))
> (define (bar x) (+ x 5))
> (define-syntax bar (syntax-rules () ((_ x) (+ x 5))))
> 
>     the 2 definitions of bar work "the same".  However, IMO, the second
> definition should yield an  error in  (foo 4)  because it's evaluation time 
> and bar evaluates to a macro, and 5 is not "syntax". 
>     Mainly, however, I see this as a kind of lexical scoping - if you 
> re-evaluated macros whenever they changed, you have a kind of 
> dynamic scope.  I know this was characterized by Marius in the opposite
> way in the earlier (late 2000) discussion.  I.e. that because macro expanding
> at read time captures whatever value of the syntax binding was lying around
> rather than the binding itself (to be used over and over), it is "dynamic".  Well,
> I don't have a great counter to this, it's just my intuition says that expanding
> at read time gives you a "what you get is what you write" promise of 
> lexicality.  Or actually that the other scheme is even more dynamic than 
> expanding at read  time.  Besides which the expansion stage is supposed to 
> occur (completely) before either interpretation or compilation, not intertwined
> with it.  I guess I sort of see define-syntax as implicitly introducing a new,
> inescapable and non-bracketed scope.  
>     Probably the most compelling reason to expand at read time, though is that
> any sane compilation system would not go re-compiling every bit of code just
> because someone redefines lambda or if at the repl.

I agree with you that re-compilation in case of a macro redefinition is of
questionable worth.  Moreover, I don't see a demand for it:  Guile does
not provide such a feature, and I can't remember that I ever saw a user
requesting it on the list.

But, IMO the way guile currently does it is broken (IMO).  Look at the
following example:

(define (foo x) (if x (bar) (bar)))
(defmacro bar () ''first)
(foo #t)
--> first
(defmacro bar () ''second)
(foo #t)
--> first
(foo #f)
--> second
(foo #t)
--> first

First, we see that macro expansion happens during evaluation.  Otherwise,
if expansion was done after 'read, the references to 'bar would not be
expanded: 'bar is not known to be a macro at that time.

Second, we see that there is no re-compilation.  Otherwise the second
execution of (foo #t) would have resulted in 'second.

Third, we see that macro expansion is only done in those paths which are
actually executed.  Otherwise after the first execution of (foo #t) _all_
references to 'bar would have been replaced by 'first.

IMO, the current solution is broken.  Depending on the evaluation order
and the actual execution paths that are taken, you can get completely
different expansions, although the code is syntactically the same.  It is
easy to create an example where it depends on _input data_ how the
expansion will be done.  Ugh.

Thus, I sugggest to first go the way that Lynn suggests: Do expansion
after reading, but don't care about re-compilation.  If we later decide
for re-compilation, we can think about possible solutions then.

Best regards
Dirk Herrmann


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


  reply	other threads:[~2002-04-13  9:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-06  6:25 Syntax checks Dirk Herrmann
2002-04-06 15:38 ` Neil Jerram
2002-04-07  7:09   ` Dirk Herrmann
2002-04-08 18:27     ` Neil Jerram
2002-04-07 10:40   ` Marius Vollmer
2002-04-09 20:48     ` Lynn Winebarger
2002-04-13  9:01       ` Dirk Herrmann [this message]
2002-04-13 12:48         ` Neil Jerram
2002-04-13 18:28           ` Lynn Winebarger
2002-04-13 18:10         ` Lynn Winebarger
2002-04-14 18:18           ` Marius Vollmer
2002-04-14 18:11         ` Marius Vollmer
2002-04-23 21:55         ` Thien-Thi Nguyen
2002-04-14 17:52       ` Marius Vollmer
2002-04-29 23:55         ` Lynn Winebarger
2002-05-07 19:24           ` Marius Vollmer
2002-05-09  5:59             ` Lynn Winebarger
2002-04-07 10:05 ` Marius Vollmer

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=Pine.LNX.4.21.0204131032500.22358-100000@marvin.ida.ing.tu-bs.de \
    --to=dirk@ida.ing.tu-bs.de \
    --cc=guile-devel@gnu.org \
    --cc=mvo@zagadka.ping.de \
    /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).