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 get-free-port [] | |
(with-open [socket (ServerSocket. 0)] | |
(.getLocalPort socket))) |
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
;; An implementation of the rock-paper-scissors variant - | |
;; rock-paper-scissors-lizard-spock - based on Alex Miller's core.async | |
;; implementation. | |
;; - http://tech.puredanger.com/2013/07/10/rps-core-async/ | |
;; - https://gist.github.com/puredanger/5965883 | |
;; - https://github.com/relevance/labrepl/blob/master/src/solutions/rock_paper_scissors.clj | |
;; - http://www.imdb.com/title/tt1256039/quotes?item=qt0493730 | |
(require 'clojure.core.async :refer :all) |
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
(require 'clojure.core.async :refer :all) | |
(def MOVES [:rock :paper :scissors]) | |
(def BEATS {:rock :scissors, :paper :rock, :scissors :paper}) | |
(defn rand-player | |
"Create a named player and return a channel to report moves." | |
[name] | |
(let [out (chan)] | |
(go (while true (>! out [name (rand-nth MOVES)]))) |
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 pipe | |
"Returns a vector containing a sequence that will read from the | |
queue, and a function that inserts items into the queue. | |
Source: http://clj-me.cgrand.net/2010/04/02/pipe-dreams-are-not-necessarily-made-of-promises/" | |
[] | |
(let [q (LinkedBlockingQueue.) | |
EOQ (Object.) | |
NIL (Object.) | |
s (fn queue-seq [] |