This does work quite nicely with trampoline, though:
(letfn [(a [n] #(if (zero? n) n (b (dec n))))
(b [n] #(if (zero? n) n (c (dec n))))
(c [n] #(if (zero? n) n (a (dec n))))]
(trampoline c 100000))
--Chouser
> I've added letfn, which lets you define mutually recursive local
> functions a la CL's labels.
>
> (defn ring [n]
> (letfn [(a [n] (if (zero? n) n (b (dec n))))
> (b [n] (if (zero? n) n (c (dec n))))
> (c [n] (if (zero? n) n (a (dec n))))]
> (c n)))
I noticed that letfn does not permit destructuring in its argument
lists:
(letfn [(a [[f & r]] f)]
(a [1 2 3]))
java.lang.IllegalArgumentException: fn params must be Symbols
(NO_SOURCE_FILE:2)
Is this intentional?
Konrad.
Fixed in svn 1317 - thanks for the report.
Rich
Do you advocate usage of 'letfn' and 'let' similar to the distinction
between LABELS and FLET in CL? In other words, FLET implies non-
recursive local function definition whereas LABELS suggests
(mutually) recursive function(s).
So,
(letfn [(f [x] (+ x 2))] (f 8)) ; LABELS
should ideally be:
(let [f (fn [x] (+ x 2))] (f 8)) ; FLET
Aloha,
David Sletten