I don't think you need the declare line in your example, since the
recursive references are inside of closures.

I think your code is already very elegant, in the sense that it almost
directly mirrors the mathematical definition of the sequences.  There
are probably ways to make it more efficient (for example, you could
create a custom memoization for these functions that stores things
internally in a vector, taking advantage of the fact that these inputs
are numbers, and are always being generated sequentially.  But this
would certainly make the code less elegant.

The only thing I can think of that is more "elegant" would be to
combine the sequence/generating function/memoization into one thing:
(def natural-numbers (iterate inc 1))
(declare hmale-seq hfemale-seq)
(def hmale-seq (cons 0 (for [n natural-numbers] (- n (nth hfemale-seq
(nth hmale-seq (dec n)))))))
(def hfemale-seq (cons 1 (for [n natural-numbers] (- n (nth hmale-seq
(nth hfemale-seq (dec n)))))))

But this is going to be less efficient than your version, because it
has to do a linear seek through the sequence to find the cached value.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to