Counting without numbers

unsorted — cgrand, 4 May 2009 @ 20 h 09 min

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


(loop [state init, n (seq some-seq)]
  (if n
    (recur value (next n))
    (ends here)))


No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2023 Clojure and me | powered by WordPress with Barecity