Greetings,

I'm new to Clojure and working my way through Project Euler problems
for learning. I wrote function for calculating prime number below some
integer value max. But it doesn't work for large numbers, causing
StackOverflowError.

(defn primes-below
        "calculates all primes bellow max"
        [max]
        (loop [numbers (range 2 max) primes []]
                (if (empty? numbers)
                        primes
                        (let [p (first numbers)
                              numbers (filter #(pos? (rem % p)) numbers)
                              primes (cons p primes)]
                          (recur numbers primes)))))

(primes-below 2000000)

I guess problem is not with loop-recur, or am I wrong?

Thanks in advance.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to