[plt-scheme] Re: a few questions
Gregory Woodhouse wrote:
>
> 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))))
...
> (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.)
You forgot a parenthesis before the lambda in the lp-clause:
(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 '() '()))))
(Note: [] and () mean the same)
--
Jens Axel Søgaard