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))))
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---