-
-
Save cgrand/1236838 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
; juste pour l'art | |
(defn primes [] | |
(keep :prime | |
(iterate (fn [{:keys [known candidate]}] | |
(if (some #(zero? (rem candidate %)) known) | |
{:known known :candidate (inc candidate)} | |
{:known (conj known candidate) :candidate (inc candidate) :prime candidate})) | |
{:known [] :candidate 2}))) | |
(def primes | |
(lazy-seq (cons 2 (remove (fn [candidate] (some #(zero? (rem candidate %)) (take-while #(< % candidate) primes))) | |
(iterate inc 3))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
L11-13 l'exemple même de code trop malin pour son propre bien : utilise la mutation de manière cachée, dépend du caractère non-chunké de (iterate inc 3).
Clojure n'est pas Haskell, la paresse ne sert pas les mêmes objectifs. En Haskell c'est à la base du contrôle du flot d'exécution, en Clojure c'est juste le "media" du traitement, comme les pipes unix.