Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scope of the name of a named let; bugs in SRFI 5 and scm

21 views
Skip to first unread message

Allegro Petrofsky

unread,
Jul 5, 1999, 3:00:00 AM7/5/99
to
In r5rs and r4rs (I didn't look any further back), the scope of the
name of a named let encloses only the body of the let and not the
initialization values of the bound variables. Thus we have:

(let ((f -)) (let f ((n (f 1))) n)) => -1

However, in scm and guile this evaluates to 1. Kawa gets it right. I
didn't try any other implementations.

More disturbingly, SRFI 5 "A compatible let form with signatures and
rest arguments" unintentionally defines semantics for named let that
are incompatible with r5rs. SRFI 5 has already been given irrevocable
final status, so I suppose a fixed version needs to be proposed with a
new number and SRFI 5 marked deprecated.

The fix is to take these lines from the semantics section of SRFI 5:

($letrec ((<name> ($lambda (<parameter>...) <body>...)))
(<name> <argument>...))

($letrec ((<name> ($lambda (<parameter>... . <rest-parameter>) <body>...)))
(<name> <argument>... <rest-argument>...))

and change them to:

(($letrec ((<name> ($lambda (<parameter>...) <body>...))) name)
<argument>...)

(($letrec ((<name> ($lambda (<parameter>... . <rest-parameter>) <body>...)))
<name>)
<argument>... <rest-argument>...)

which match the derived expression definition from r5rs:

(define-syntax let
(syntax-rules ()
((let ((name val) ...) body1 body2 ...)
((lambda (name ...) body1 body2 ...)
val ...))
((let tag ((name val) ...) body1 body2 ...)
((letrec ((tag (lambda (name ...)
body1 body2 ...)))
tag)
val ...))))

A similar change needs to be made to the implementation section of
SRFI 5.

-al

Rob Warnock

unread,
Jul 6, 1999, 3:00:00 AM7/6/99
to
Allegro Petrofsky <All...@Petrofsky.Berkeley.CA.US> wrote:
+---------------

| (let ((f -)) (let f ((n (f 1))) n)) => -1
| However, in scm and guile this evaluates to 1. Kawa gets it right.
| I didn't try any other implementations.
+---------------

MzScheme, Elk, & Scsh (Scheme48) get it wrong, too, but Gambit and RScheme
get it right.

Note that even the ones that get it wrong when written as a named-let
work correctly if you write out the R[45]RS expansion manually:

(let ((f -))
((letrec ((f (lambda (n) n)))
f)
(f 1))) ==> -1


-Rob

-----
Rob Warnock, 8L-855 rp...@sgi.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA

Richard Kelsey

unread,
Jul 7, 1999, 3:00:00 AM7/7/99
to
In article <7lsfh1$6d...@fido.engr.sgi.com>,

Rob Warnock <rp...@rigden.engr.sgi.com> wrote:
>Allegro Petrofsky <All...@Petrofsky.Berkeley.CA.US> wrote:
>+---------------
>| (let ((f -)) (let f ((n (f 1))) n)) => -1
>| However, in scm and guile this evaluates to 1. Kawa gets it right.
>| I didn't try any other implementations.
>+---------------
>
>MzScheme, Elk, & Scsh (Scheme48) get it wrong, too, but Gambit and RScheme
>get it right.

Scsh gets it wrong but the current Scheme48 gets it right. Scsh is
based on a version of Scheme48 from early 1994 (version 0.36) and
this bug was fixed in early 1995 (version 0.40). The current version
is 0.52 and can be found at http://www.neci.nj.nec.com/homepages/kelsey/ .

-Richard Kelsey

Rob Warnock

unread,
Jul 8, 1999, 3:00:00 AM7/8/99
to
Richard Kelsey <kel...@kima.nj.nec.com> wrote:
+---------------

| Rob Warnock <rp...@rigden.engr.sgi.com> wrote:
| >MzScheme, Elk, & Scsh (Scheme48) get it wrong, too, but Gambit and RScheme
| >get it right.
|
| Scsh gets it wrong but the current Scheme48 gets it right. Scsh is
| based on a version of Scheme48 from early 1994 (version 0.36) and
| this bug was fixed in early 1995 (version 0.40).
+---------------

Oh, o.k. Thanks for the correction, and sorry for the unintended
disparagement of the current Scheme48...

Andy Gaynor

unread,
Jul 14, 1999, 3:00:00 AM7/14/99
to
Any SRFI folks monitoring this discussion?
Should I evaluate Allegro's fix and resubmit,
or have you taken care of it?

Lazily sluggish, [Ag] Andy Gaynor sil...@mail.webspan.net

Michael Sperber [Mr. Preprocessor]

unread,
Jul 14, 1999, 3:00:00 AM7/14/99
to Andy Gaynor
>>>>> "Andy" == Andy Gaynor <sil...@mail.webspan.net> writes:

Andy> Any SRFI folks monitoring this discussion?

Yes.

Andy> Should I evaluate Allegro's fix and resubmit,

I did recommend to the guy who posted it that he submit a SRFI.
Nothing happened, so if you want to, by all means do submit a new one.

Andy> or have you taken care of it?

No :-)

--
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

Paul Steckler

unread,
Jul 14, 1999, 3:00:00 AM7/14/99
to
Rob Warnock (rp...@rigden.engr.sgi.com) wrote:
: Allegro Petrofsky <All...@Petrofsky.Berkeley.CA.US> wrote:
: +---------------
: | (let ((f -)) (let f ((n (f 1))) n)) => -1
: | However, in scm and guile this evaluates to 1. Kawa gets it right.
: | I didn't try any other implementations.
: +---------------
:
: MzScheme, Elk, & Scsh (Scheme48) get it wrong, too, but Gambit and RScheme
: get it right.

Appears to be fixed in the 100alpha4 version of MzScheme, about
to go out the door.

-- Paul

----------------------------------------------------------------
| Paul Steckler | Rice University PLT |
| st...@cs.rice.edu | DrScheme Project |
| Tel: 713/527-8101x3814 | http://www.cs.rice.edu/~steck |
| FAX: 713/285-5930 | *** Ad astra per hackera *** |
----------------------------------------------------------------

0 new messages