chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Binding identifiers with set!


From: felix
Subject: Re: [Chicken-users] Binding identifiers with set!
Date: Tue, 14 Oct 2003 00:18:08 +0200
User-agent: Opera7.11/Linux M2 build 406

On 13 Oct 2003 09:24:26 +1300, Bruce Hoult <address@hidden> wrote:

The thing that I dislike *more* is the (documented) way that Chicken
makes "define", other than at the start of a lambda-or let-body,
exactly equivalent to set!.  i.e. per r5rs a define at the start of a
body is exactly the same as a "let" (and several are the same as a
"letrec") and creates a local lexical binding with the rest of the body
inside the "let", but if you put so much as a debug output statement
before one of the defines then it suddenly modifies (or, per your
complaint, creates!) a toplevel variable instead of a local binding. This has caught me out more than once.

My own preference would be for *every* non-toplevel "define" being the
same as a "let" having the rest of the body as its scope.  Which means
that a series of "defines" is effectively a "let*".

This would be in line with the way that local bindings work in Dylan or
C++ or almost any other modern language. Unfortunately it is in conflict
with r5rs at the start of a lambda-or let-body because r5rs requires a
sequence of "define"s to be "letrec", not "let*"  :-( :-(


Well, you could handle this by treating every sequence of local defintions
as a letrec. So for example

(let (...)
 (define foo 1)
 (define bar 2)
 (print "oink!")
 (define baz 3)
 (define quux 4)
 ...)

would expand into:

(let (...)
 (letrec ([foo 1] [bar 2])
   (print "oink!")
   (letrec ([baz 3] [quux 4])
     ...) ) )

This would be compliant to R5RS (for the first set of definitions).

Would this be useful?


cheers,
felix





reply via email to

[Prev in Thread] Current Thread [Next in Thread]