Skip to content

Instantly share code, notes, and snippets.

@laurentpetit
Forked from denlab/gist:1231894
Created September 21, 2011 21:56
Show Gist options
  • Save laurentpetit/1233437 to your computer and use it in GitHub Desktop.
Save laurentpetit/1233437 to your computer and use it in GitHub Desktop.
coding-dojo-20110921
(defn primes []
((fn primes [candidate seen]
(lazy-seq
(letfn [(prime? [candidate] (when-not (some #(zero? (rem candidate %)) seen) candidate))]
(when-let [candidate (some prime? (iterate inc candidate))]
(cons candidate (primes (inc candidate) (cons candidate seen)))))))
2 ()))
(fact
(primes 1) => (2)
(primes 2) => (2 3)
(primes 3) => (2 3 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment