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

From: Bill Wood (william.wood3 at comcast.net)
Date: Sun Dec 4 19:55:45 EST 2005

On Sun, 2005-12-04 at 14:30 -0800, Gregory Woodhouse wrote:
   . . .
> Is LABELS a special form in some  version of scheme, or something  
> bound by an enclosing let? Something else?

Just a historical note:  The LISP 1.5 Programmer's Manual, 2nd ed.,
(MIT, 1965) uses the form (LABEL <name> <lambda-expression>) to bind a
name to a lambda expression.  Also, the Common Lisp form
(labels ( <fun-binding> ... ) <expr> ... ) corresponds to the Scheme
letrec form, with the restriction that a labels form introduces bindings
for functions only, whereas a letrec form can introduce bindings to any
values, including lambda expressions.

I don't know if the Y combinator had been devised when McCarthy was
trying to computerize recursion theory, but he was clearly using the
label form as a means of giving an anonymous function a name to hook
recursion to.  In particular, a label expression could be applied just
as a lambda expression could.

Here's the same silly loop done with Scheme's named let and letrec
forms, McCarthy's label form and the Common Lisp labels form:

NAMED LET:  (let loop ((n 3) (acc 0))
              (if (positive? n)
                  (loop (- n 1) (+ acc n))
                  acc))

LABEL:  ((label loop (lambda (n acc)
                       (if (positive? n)
                           (loop (- n 1) (+ acc n))
                           acc)))
         3 0)

LETREC: (letrec ((loop (lambda (n acc)
                         (if (positive? n)
                             (loop (- n 1) (+ acc n))
                             acc))))
          (loop 3 0))

LABELS: (labels ((loop (n acc)
                   (if (plusp n)
                       (loop (- n 1) (+ acc n))
                       acc)))
          (loop 3 0))

 -- Bill Wood




Posted on the users mailing list.