-
-
Save laurentpetit/1233437 to your computer and use it in GitHub Desktop.
coding-dojo-20110921
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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