Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn primes []
((fn primes [candidate seen]
(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 ()))
(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
You can’t perform that action at this time.