A few observations:

I believe what you have implemented is trial division
<http://en.wikipedia.org/wiki/Trial_division>, rather than the SoE.

It looks a little weird to me to have a predicate called `not-foo?`
starting with a call to `not`. I would rather define a `foo?` predicate,
and then do `(def not-foo? (complement foo?))` if needed.

The `div-nums` function is used only to generate odd numbers greater than
2, but the built in `range` can do that admirably with `(range 3 n 2)`.

In general, `(for [x coll :when (pred x)] x)` can be more idiomatically
spelled `(filter pred coll)`.

`(empty? (filter pred coll))` can be spelled `(not-any? pred coll)`

`(= n 0)` can be spelled `(zero? n)` [thanks, kibit
<https://github.com/jonase/kibit>!]

Here's my go <https://gist.github.com/ahammel/58cdfd0fe57cc35e71f1>.

Cheers,
Alex

On Wed, Nov 26, 2014 at 6:52 AM, Chernyshev Alex <
chernyshev.alexan...@gmail.com> wrote:

> (defn not-divisible-by?[num denum]
>   (not (= (mod num denum) 0)))
>
> (defn div-nums [denum bound]
>     (for [x (range 2 bound) :when (not-divisible-by? x denum)] x))
>
> (defn divisible? [coll denum]
>   (empty? (filter #(and (not= denum %) (not(not-divisible-by? denum %)))
> coll)))
>
> (defn generate-primes
>   "Sieve of Eratosthenes"
>   [n]
>   (let [src (div-nums 2 n)]
>     (cons 2 (for [x src :when (divisible? src x)] x))))
>
>
>  --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to