Last active
December 12, 2015 06:08
-
-
Save gorsuch/4726919 to your computer and use it in GitHub Desktop.
some clojure queue business
This file contains hidden or 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 q (atom '())) | |
(defn qpush! [queue value] | |
(swap! queue conj value)) | |
(defn qpop! [queue] | |
(let [q @queue | |
v (first q) | |
nq (pop q)] | |
(if (compare-and-set! queue q nq) v (recur queue)))) | |
(defn clear [queue] | |
(swap! queue (fn [x] '()))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment