i made a lazy prime number seive, and it seems to work for a while:

(defn natural [] (iterate #(+ % 1) 1))
(def primes
     ;;takes a sorted set of counters and a seq of numbers to filter
     ((fn sieve [in-counters checked]
        ;;first part of the cons is the first in said seq. hurray!
          (lazy-cons (first checked)
                     ;;this bit takes the set of counters, and the unchecked seq
                     (loop [counts in-counters
                            unchecked (rest checked)]
                       (let [count (first counts)
                             [c p] count
                             u (first unchecked)]
                         ;;if first in seq = a counter, composite -> try next 
in seq
                         (cond (= c u) (recur counts
                                              (rest unchecked))
                               ;;if the counter is smaller, increment it and 
try again
                               (< c u) (recur (conj (disj counts
                                                          count)
                                                    [(+ c p) p])
                                              unchecked)
                               ;;if the counter is bigger, first in seq is prime
                               (> c u) (sieve (conj counts
                                                    [(* u u) u])
                                              unchecked))))))
      ;;feed it a set with 2's counter and a seq from 2
      (sorted-set [4 2])
      (rest (natural))))


i tried it out with:
(doseq [p primes] (println p))

here's the tail end of it:
46301
46307
46309
46327
46337
java.lang.RuntimeException: java.lang.ClassCastException:
java.lang.Integer cannot be cast to java.lang.Long (NO_SOURCE_FILE:0)


any ideas what's going on here?
--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to