[plt-scheme] to define, or to let

From: Anton van Straaten (anton at appsolutions.com)
Date: Sun Mar 21 03:08:45 EST 2004

Felix Klock wrote:
> The MzScheme extension to the semantics of LETREC is
> technically legal according to R5RS

I believe that's incorrect.  As Bradd has pointed out, this was discussed in
depth on c.l.s.:

I'll summarize:

The standard defines some semantics [4.2.2, after "Semantics:"], and then
makes a strong point about a
"very important restriction" which follows from those semantics.  It also
encodes the specified semantics in the letrec macro in 7.3.

To achieve the letrec extension in question, the specified semantics cannot
reasonably be followed.  Not detecting violation of the restriction
specified in R5RS is within the bounds of the standard.  However, *lifting*
the restriction effectively requires violating the specified semantics.
Arguing that lifting the restriction qualifies as "is an error" behavior
doesn't work, because to lift the restriction requires implementing a
construct that doesn't follow the specified semantics for all cases, not
just "error" cases.  (The specified semantics make it impractical to both
conform to the specified semantics and support the extension.)

So, I believe the letrec extension is a clear violation of R5RS.

However, I found that something like 16 implementations of Scheme, including
PLT, implement this extension.  Apparently, this was done for pragmatic
reasons before anyone noticed that ignoring the specified semantics was

Al* Petrofsky pointed out that "when this issue of widespread letrec
non-conformance was first pointed
out in 1992, Will Clinger said: 'There isn't any great rush to settle this,
because no one in his/her right mind would write a program that depends on

Oleg subsequently posted the following in haskell-cafe (possibly avoiding
c.l.s. for fear of having his sanity questioned?) :

This provides a short, meaningful test, which demonstrates concrete negative
consequences of the letrec extension.  This example illustrates the point
that using code which relies on call/cc in conjunction with letrec -
including library code - is not portable between Scheme implementations,
purely because of the violation of the standard in this area.

> Therefore, the extension should remain as 100% legal code for
> the PLT family of languages

Since this non-conformance is so widespread among Scheme implementations,
and since fixing it would break existing code, it will certainly remain
legal for most implementations.

> However, for the Standard (R5RS) language, DrScheme should (at least)
> print a warning for such uses of LETREC.

I'm not sure how easy violations are to detect.  It would be easier, and
make more sense IMO, to implement the standard letrec for the PLT R5RS
language.  I suspect that might not be popular, though.


Posted on the users mailing list.