[plt-scheme] Re: a few questions (was: Scheme questions?)
On Dec 4, 2005, at 2:36 PM, Carl Eastlund wrote:
> If I recall correctly, LABELS is an old form of letrec.
Hmm...Trying to (somewhat mechanically) translate
(DEFINE FACT
(LAMBDA (N)
(LABELS ((L1 (M ANS)
(LP N 1)))
(LP (LAMBDA (M ANS)
(IF (= M 0) (RETURN ANS)
(L2 M ANS))))
(L2 (LAMBDA (M ANS)
(LP (- M 1) (* M ANS))))
(L1 NIL NIL))))
(from the same paper), I get
Welcome to DrScheme, version 299.407-svn4dec2005.
Language: Pretty Big (includes MrEd and Advanced Student).
> (define fact
(lambda (n)
(letrec ((l1 (lambda(m ans)
(lp n 1)))
(lp lambda (m ans)
(if (= m 0) ans
(l2 m ans))))
(l2 (lambda (m ans)
(lp (- m 1) (* m ans)))))
(l1 '() '())))
letrec: bad syntax in: (lp lambda (m ans) (if (= m 0) ans (l2 m ans)))
>
(I don't know what RETURN is, but I assume it's an escape, and so I
would have thought replacing (RETURN ANS) with just ans would work,
or at least be syntactically valid.)
===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net
"You must unlearn what you have learned."
--Yoda