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
(def x (ref 0)) | |
(def a (agent nil)) | |
(defn alter-and-send-side-effects | |
"Alters refs then sends println actions to agent with new values" | |
[] | |
(dosync | |
(let [newx (alter x inc)]) | |
(send a (fn [_] (println "x is" newx))))) |
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 primes3 [max] | |
(let [enqueue (fn [sieve n factor] | |
(let [m (+ n (+ factor factor))] | |
(if (sieve m) | |
(recur sieve m factor) | |
(assoc sieve m factor)))) | |
next-sieve (fn [sieve candidate] | |
(if-let [factor (sieve candidate)] | |
(-> sieve | |
(dissoc candidate) |
NewerOlder