[plt-scheme] semantics of letrec in Lazy Scheme

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Jun 2 09:32:11 EDT 2009

On Jun  2, Keiko Nakata wrote:
> 
> I am also looking at another behavior which I do not understand:
> 
> > (define-values (v0 v1)
> >   (letrec ([x (begin (set! y 4) (print 0) 0)]
> >            [y (begin (print 1) 1)])
> >     (values x y)))
> > (force v0)
> 00
> > (force v1)
> 11
> 
> But I could think this is also a side-effect of the same optimization.

Yeah -- you can see the expected result if you change the last line to
something like:

  (define-values (v0 v1)
    (letrec ([x (begin (set! y 4) (print 0) 0)]
             [y (begin (print 1) 1)])
      (values x (begin 0 y))))

(FWIW, the lazy language needs some major overhaul which I didn't get
to yet.  It might be possible to make it much faster without requiring
such an optimization.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.