[plt-scheme] Re: a few questions (was: Scheme questions?)

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sun Dec 4 17:36:10 EST 2005

On 12/4/05, Gregory Woodhouse <gregory.woodhouse at sbcglobal.net> wrote:
>
> Okay, as a newcomer to the language, letrec seems reasonably
> intuitive to me, named let is mysterious. (I think of letrec as
> binding a set of symbols to lambda expressions, where the expressions
> may involve mutual recursion. It seems to me that in
>
> (let whatever ((..)...)
>
> whatever is used in the body of the expression as if though it were
> itself a lambda expression, but how this works (and what the correct
> syntax is) seems rather mysterious.

"Named" let is really a misnomer, it's a form that does several things
at once and "let" is the least of them.  What named-let does is
declare a local recursive function and call it at once.  The code:

(let LOOP ([VAR VALUE] ...) BODY)

is equivalent to:

(letrec ([LOOP (lambda (VAR ...) BODY)]) (LOOP VALUE ...))

where my use of ellipses is as in syntax-rules and syntax-case.  I
hope this at least starts to clear things up.

> I know this is an old paper, but in "Lambda: The Ultimate
> Imperative"  (1976),  Guy L. Steele uses some syntax that I don't
> recognize at all.  Something like
>
> (LABELS ((L1 (LAMBDA ()
>                         (IF B1 (L2)
>                             (BLOCK S1
>                                    (IF B2 (L2)
>                                        (BLOCK S2 (L1))))))))
>            (L2 (LAMBDA () S3))
>            (L1))
>
> Is LABELS a special form in some  version of scheme, or something
> bound by an enclosing let? Something else?

If I recall correctly, LABELS is an old form of letrec.

--Carl


Posted on the users mailing list.