Week 2: Circuit Simulation, Functional Wires
Mmm actually I think that write Protocol and Record is not so so "Clojure's Style".
What do you think about this implementation?
I'm learning Clojure.. I'm not a Guru so I'm trying to always improve my "Clojure Functional Style".
I'll really appreciate any opinion you have on this!! :D
What do you think about this implementation?
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
(def ^:private actions :actions) | |
(def ^:private sigVal :sigVal) | |
(defn wire [s a] {sigVal s, actions a}) | |
(defn- update-with [w k v f] (assoc w k (f w v))) | |
(defn- launch-actions [w s] | |
(let [_ (if (not= s (w get-signal)) (doall (map #(%) (w actions))))] | |
s)) | |
(defn- cons-actions [w a] (cons a (actions w))) | |
(defn get-signal [wire] (sigVal wire)) | |
(defn set-signal [w s] (update-with w sigVal s launch-actions)) | |
(defn add-action [w a] (update-with w actions a cons-actions)) |
I'll really appreciate any opinion you have on this!! :D
Comments
Post a Comment