Following a recent tweet, I’m setting up a Clojure training session with Lau B. Jensen and we’d like to know more about our potential attendees. Please fill this short survey:
(click here if you don’t see the above form.)
Because of the spinning nature of atoms, it’s kind of a hack (a fun hack but still a hack) to build queues on it. Here is the same pipe
function built on Java queues:
(defn pipe []
(let [q (java.util.concurrent.LinkedBlockingQueue.)
EOQ (Object.)
NIL (Object.)
s (fn s [] (lazy-seq (let [x (.take q)]
(when-not (= EOQ x)
(cons (when-not (= NIL x) x) (s))))))]
[(s) (fn ([] (.put q EOQ)) ([x] (.put q (or x NIL))))]))