[plt-scheme] about letrec and continuation : which behavior is correct ? and why ?

From: Abdulaziz Ghuloum (aghuloum at cs.indiana.edu)
Date: Wed Aug 20 11:20:04 EDT 2008

On Aug 19, 2008, at 2:48 PM, Joe Marshall wrote:

> On Tue, Aug 19, 2008 at 7:44 AM, Abdulaziz Ghuloum
> <aghuloum at cs.indiana.edu> wrote:
>> On Aug 19, 2008, at 7:10 AM, Matthew Flatt wrote:
>>> The R5RS/R6RS `letrec' is different, and the result with that
>>> other `letrec' should be #f:
> I've always thought this was a wart in the language.

Fine, but how else would letrec be implements in order to provide
the full generality of letrec (letrec is not fix) and at the same
time obey the other rules of the imperative, strict, call-by-value
language known as Scheme?  E.g., how would you evaluate

   (letrec ([x (list (lambda () x))])
     (eq? x ((car x)))) ; => #t

without a side effect?

>> An R6RS implementation may (or may not) raise an &assertion when
>> the <init> continuation is invoked the second time, right?
> Ugh.  That's worse than the SET! expansion.

Returning to an <init> continuation may (1) rebind the variable
as Matthias showed, (2) assign to an already existing binding as
Matthew showed, or (3) raise an assertion as the report suggests.

Rebinding is not always possible since there is no known general
letrec transformation that eliminates side effects.  Options 2
and 3 are always possible for all shapes of letrec, but they're
ugly as you suggest.  Where does that leave us?


Posted on the users mailing list.