Skip to content

Instantly share code, notes, and snippets.

@pbostrom
pbostrom / gist:3250162
Created August 3, 2012 18:21
Transaction side effects
(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)))))
@pbostrom
pbostrom / sieve.clj
Created July 9, 2012 02:39
Clojure Sieve of Eratosthenes - Christophe Grand
(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)