[plt-scheme] How is letrec different from letrec* in its use?

From: Sam TH (samth at ccs.neu.edu)
Date: Thu Feb 12 22:58:55 EST 2009

The following program does not have a consistent meaning under all
orders of evaluation of the `letrec' right-hand-sides.

(letrec ([x 1]
            [y (set! x 2)]
            [z (set! x (+ x 1))])

For example, if we evaluate the bindings top down, we get 3, but if we
evaluate z before y, we get 2.  The semantics for `letrec' do not
specify which of these you might get (indeed, you might get an error
from +).  The semantics of `letrec*' will always give you 3.

sam th

On Thu, Feb 12, 2009 at 10:45 PM, Grant Rettke <grettke at acm.org> wrote:
> Hi folks,
> I just read the spec for both letrec and letrec* and I see that the
> former is not evaluted in any other but the latter is evaluted from
> left to right. I am not getting the difference in their use. May
> someone please provide an illuminating example?
> Best wishes,
> Grant
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

sam th
samth at ccs.neu.edu

Posted on the users mailing list.