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: Bruce Hoult
Subject: Re: [Chicken-users] Binding identifiers with set!
Date: 13 Oct 2003 09:24:26 +1300

On Sun, 2003-10-12 at 22:19, Category 5 wrote:
> In <address@hidden> on
> comp.lang.scheme, Anton van Straaten pointed out that set! can be used
> to introduce new bindings in Chicken:
> 
> % csi
> ; This is the CHICKEN interpreter.
> ; Version 1, Build 17 - netbsd-gnu-ultrasparc
> ; (c)2000-2003 Felix L. Winkelmann
> >>> foo
> Error: unbound variable: foo
> >>> (set! foo 1)
> >>> foo
> 1
> >>>
> 
> This clearly doesn't jive with R5RS (5.2.1):

I agree that this increases the chance of accidents.

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*"  :-( :-(

-- 
Bruce Hoult <address@hidden>





reply via email to

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