Clojure and me has moved.

Monday, May 4, 2009

Counting without numbers

This post has moved, go to its new location
I was writing something along these lines:
(loop [state init, n (count some-seq)]
(if (pos? n)
(recur value (dec n))
(ends here)))
when it struck me that seqs are numerals too!
(loop [state init, n some-seq]
(if (seq n)
(recur value (rest n))
(ends here)))
or:
(loop [state init, n (seq some-seq)]
(if n
(recur value (next n))
(ends here)))

No comments: