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
| (is (= (+ 40 2) 42)) |
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
| A: 0 | |
| A: 1 | |
| B: 0 | |
| A: 2 | |
| A: 3 | |
| B: 1 | |
| C: 0 | |
| A: 4 | |
| B: 2 | |
| A: 5 |
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
| (defn pipeline [] | |
| (let [bound 10000 | |
| m-ch (chan bound) | |
| n-ch (chan bound) | |
| o-ch (chan bound)] | |
| (go (while true (put! n-ch (m (<! m-ch))))) | |
| (go (while true (put! o-ch (n (<! n-ch))))) | |
| (go (while true (o (<! o-ch)))) | |
| m-ch)) |
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
| (defn m [x] | |
| (send printer (fn [_] (println "A:" x))) | |
| (Thread/sleep 500) | |
| x) | |
| (defn n [x] | |
| (send printer (fn [_] (println "B:" x))) | |
| (Thread/sleep 1000) | |
| x) |
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
| (defn a [x] | |
| (println "A:" x) | |
| x) | |
| (defn b [x] | |
| (println "B:" x) | |
| x) | |
| (defn c [x] | |
| (println "C:" x) |
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
| (defn g [x] | |
| (throw {:a 1})) | |
| (defn f [x] | |
| (g x)) | |
| (with-pre-hook! #'f | |
| (λ [y] | |
| (prn "Got " y))) |
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
| (defn drive-forward [car speed] | |
| (let [new-front (- (:front car) speed)] | |
| (assoc car :front (max new-front 0)))) |
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
| (defn put-into-ch [channel car] | |
| (.put channel car)) | |
| (defn take-from-channel [channel] | |
| (.take channel)) | |
| (defn ch->lane [{:keys [channel state] :as entity} d-fn] | |
| (if-not (zero? (.size channel)) | |
| (add-to-lane entity (take-from-channel channel) d-fn) | |
| entity)) |
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
| (defn sim-loop! [snapshot t-fn queue speed] | |
| (let [successor (t-fn snapshot)] | |
| (send-off queue (constantly successor)) | |
| (Thread/sleep speed) | |
| (recur successor t-fn queue))) |
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
| (defn advance-cars-in-lane [{:keys [state lane] :as entity}] | |
| (assoc entity :state | |
| (clojure.core.reducers/reduce | |
| (partial advance (:speed lane) state) [] state))) |