Clojure doesn't do TCO with recursive functions--you have to use
`loop`/`recur`[1]. This is one of the (thankfully few) "gotchas" in
Clojure, at least/especially for people coming from other functional
languages (or so I assume--coming from Python, I hadn't heard that much
about TCO in the firs
Thanks, Sergio - this is a good way to construct the sieve.
It took me a little while to convince myself that it's the same, but it's
definitely a good solution.
In general, I guess it's not possible to generate an infinite sequence that
utilizes the tail-call optimization it makes sense as
Hi
You can try the following
(defn dividers [primes n]
(take-while #(<= (* % %) n) primes))
(defn prime? [primes n]
(every? #(pos? (rem n %))
(dividers primes n)))
(defn range-peek [coll]
(iterate inc (-> coll peek inc)))
(defn sieve
([] (cons 2 (lazy-seq (sieve [2]
(