Week2: Circuit Simulation, Wires
This week's first 3 videos are a introduction to state management inside a functional language, actually I can't read slides from video one, so I'll give you a Bank Account conversion in Clojure as soon as the slide will be out. In the second and the third video there isn't any code that can be usefull written in clojure (actually I can't understand what I had to learn from the third video... ). In the other videos video Martin start the implementation of a domain specifil language to simulate circuits.
This are the Wires, rewritten in Clojure:
Actually I'm thinking a lot on differences beetween this two languages.
I think that to create DSL Scala has the huge advantage of type system, but I think that if we can build these kind of DSL we will be in jail...
One great programmer in each society that will build the DSL, and all low-profile programmer that will use it without knowing anything of real Scala.
Another little consideration. What the heck is this O_o:
Ok the Scala's match is AWESOME, I said it in another post. But this is quite confusing, I had to watch the video 3 times to understand what was appening, in Clojure that are a lot of parenthesis, and someone can be frustrated from it, but here we need some parenthesis. The part with <= => it's very horrible in my opinion.
For now It's all :D, I'll come soon with the rest of Circuit implementation.
PS: The assignment will be quite a challenge .. there is also a Display for the Epidemic Simulation... I need days of 30 hours ....
This are the Wires, rewritten in Clojure:
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
(defprotocol WireSimulator | |
(getSignal [wire] "Return the signal on the wire") | |
(setSignals [wire s] "Set the signal on the wire") | |
(addAction [wire a] "Add an action on the wire that | |
will be executed from the simulator")) | |
(defrecord Wire [sigVal actions] | |
WireSimulator | |
(getSignal [wire] (:sigVal wire)) | |
(setSignals | |
[wire s] | |
(if (not= s (getSignal wire)) | |
(do (assoc wire :sigVal s) | |
(map #(%) actions)) | |
wire)) | |
(addAction | |
[wire a] | |
(assoc wire :actions (cons a (:actions wire))))) | |
(defn make-wire [] (->Wire false [])) |
I think that to create DSL Scala has the huge advantage of type system, but I think that if we can build these kind of DSL we will be in jail...
One great programmer in each society that will build the DSL, and all low-profile programmer that will use it without knowing anything of real Scala.
Another little consideration. What the heck is this O_o:
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
private def case (ag: List[Event], item: Event): List[Event] = ag match { | |
case first::rest if first.time <= item.time => first::insert(rest, item) | |
case _ => item::ag | |
} |
For now It's all :D, I'll come soon with the rest of Circuit implementation.
PS: The assignment will be quite a challenge .. there is also a Display for the Epidemic Simulation... I need days of 30 hours ....
Comments
Post a Comment