the jvm does not do TCO, loop/recur allows for functional looking
recursion on the jvm with constant stack size.
On Sat, Nov 29, 2008 at 1:25 AM, bOR_ <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> I wondered if there is a difference between using loop-recur or merely
> writing a recursive function. The main difference I found thus far was
> that the loop-recur can suffice with less arguments, but the recursive
> functions seem to be shorter, and perhaps more elegant?
>
> (defn construct-atom
> "translates a number n into an set of letters of size n"
> [construct length]
> (if (< (count construct) length)
> (construct-atom (conj construct (char (+ (rand-int amino_acids)
> 65))) length)
> construct))
>
> (defn construct-atom-loop
> "translates a number n into an set of letters of size n"
> [n]
> (let [base_construct #{}]
> (loop [construct base_construct]
> (if (< (count construct) n)
> (recur (conj construct (char (+ (rand-int amino_acids) 65))))
> construct))))
>
>
> >
>
--
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---