[plt-scheme] letrec

From: Lauri Alanko (la at iki.fi)
Date: Wed Oct 30 16:54:56 EST 2002

On Fri, Oct 25, 2002 at 10:03:01AM -0500, Robert Bruce Findler wrote:
> In Scheme, recursive definitions are really shorthand for a sequence of
> assignments. As an example, this:
>   (letrec ([x <x-exp>]
>            [y <y-exp>])
>     <body-exp>)
> is the same thing as this:
>   (let ([x #<undefined>]
>         [y #<undefined>])
>     (set! x <x-exp>)
>     (set! y <y-exp>)
>     <body-exp>)

Actually, according to R5RS it should be:

(let ((x #<undefined>)
      (y #<undefined>))
  (let ((x-temp <x-exp>)
        (y-temp <y-exp>))
    (set! x x-temp)
    (set! y y-temp)

I just noticed that mzscheme seems to do it the simple way, though,
assigning to some of the variables before all initializers are
evaluated. Could this be changed? In addition to following R5RS to the
letter, the form with temporary variables is better at catching
unportable uses of letrec that depend on a particular ordering of

Lauri Alanko
la at iki.fi

Posted on the users mailing list.