Chain call in clojure?
Posted
by Konrad Garus
on Stack Overflow
See other posts from Stack Overflow
or by Konrad Garus
Published on 2010-06-05T13:24:19Z
Indexed on
2010/06/05
13:52 UTC
Read the original article
Hit count: 315
I'm trying to implement sieve of Eratosthenes in Clojure. One approach I would like to test is this:
- Get range (2 3 4 5 6 ... N)
- For 2 <=
i
<= N- Pass my range through
filter
that removes multiplies ofi
- For
i+1
th iteration, use result of the previous filtering
- Pass my range through
I know I could do it with loop/recur
, but this is causing stack overflow errors (for some reason tail call optimization is not applied).
How can I do it iteratively? I mean invoking N calls to the same routine, passing result of i
th iteration to i+1
th.
© Stack Overflow or respective owner