[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
the point of REC , was (Re: [Chicken-users] Re: crazy behaviour in csi!)
From: |
Sunnan |
Subject: |
the point of REC , was (Re: [Chicken-users] Re: crazy behaviour in csi!) |
Date: |
Tue, 06 Dec 2005 17:41:48 +0100 |
On Mon, 2005-12-05 at 23:54 +0100, Jens Axel Søgaard wrote:
> Sunnan wrote:
> > ;; instead of:
> > (let f ((n (...)))
> > (if (zero? n) 1
> > (* n (f (- n 1)))))
> > ;; it's the exact same number of characters!
>
> Almost - note that REC returns the recursive
> function, so you need to return the function
> in the let:
>
> ((let f ((n (...)))
> (if (zero? n) 1
> (* n (f (- n 1))))
> f)
> (...))
But that does the same thing; the whole expression as such returns the
result of the recursive function in both cases. The recursive function
returned by REC is use-once-and-destroy.
And in chicken,
((rec (F N)
(if (zero? N) 1
(* N (F (- N 1))))) (...))
macroexpands to almost the same as
(let f ((n (...)))
(if (zero? n) 1
(* n (f (- n 1)))))
if I recall correctly.
BTW, your example evaluates (...) twice.
AML,
Sunnan