Skip to content

Instantly share code, notes, and snippets.

@mecdemort
Created March 16, 2011 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mecdemort/871908 to your computer and use it in GitHub Desktop.
Save mecdemort/871908 to your computer and use it in GitHub Desktop.
(use '[clojure.contrib.lazy-seqs :only [primes]]
'[clojure.set])
(def prime?
(let [mem (ref #{})
primes (ref primes)]
(fn [n]
(if (< n (first @primes))
(@mem n)
(let [[mems ps] (split-with #(<= % n) @primes)]
(dosync
(ref-set primes ps)
((commute mem union (set mems)) n)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment