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

or:

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

1 Comment »

  1. Hi there, always i used to check weblog posts here early in the morning, for the reason that i love to learn more and more.|

    Comment by sambapor — 23 September 2023 @ 12 h 09 min

RSS feed for comments on this post. TrackBack URI

Leave a comment

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