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

From: Grant Rettke (grettke at acm.org)
Date: Thu Feb 12 23:24:24 EST 2009

On Thu, Feb 12, 2009 at 9:58 PM, Sam TH <samth at ccs.neu.edu> wrote:
> 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))])
>      x)
> 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.

I see.

Reading the R6RS specification of letrec it says:

"It should be possible to evaluate each <init> without assigning or
referring to the value of any <variable>. In the most common uses of
letrec, all the <init>s are lambda expressions and the restriction is
satisfied automatically."

Why letrec is included when it would only work in a predictable manner
when the <init>s are lambda expressions?

Posted on the users mailing list.