Hi Everyone,
I was just wondering, how do you define a recursive lambda expression?
Lets say I want a factorial function:
(defun fact (n)
(* n (fact (- n 1))))
In scheme I could say:
(letrec ((temp-fact (lambda (n)
(* n (temp-fact (- n 1)))))))
And that would work just fine (give or take a couple parens, since I'm
not using a lisp-friendly editor).
Is there an equivalent expression in Common Lisp?
On 7 Feb 2005 15:45:49 -0800, "rhat" <·········@gmail.com> wrote:
> I was just wondering, how do you define a recursive lambda
> expression?
> Lets say I want a factorial function:
> (defun fact (n)
> (* n (fact (- n 1))))
> In scheme I could say:
> (letrec ((temp-fact (lambda (n)
> (* n (temp-fact (- n 1)))))))
>
> And that would work just fine (give or take a couple parens, since
> I'm not using a lisp-friendly editor).
>
> Is there an equivalent expression in Common Lisp?
Sure, LABELS.
<http://www.lispworks.com/documentation/HyperSpec/Body/s_flet_.htm>
* (labels ((fact (n) (if (zerop n) 1 (* n (fact (1- n))))))
(fact 100))
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")