Looks like we are going into the Software Transactional memory (stm). hmm it seems we are getting into Threading here. Making sure data is locked down by restricting what can access it. Apparently this is done through these things in Clojure called references. We’ll see…
So references can only be edited within a transaction, not afterwards. You have to do a little command called dosync in order to deref something and then alter it.
wow.. atoms, and references and what can be edited how and when? …. exactly! This stuff if hard to get my head around but apparently atoms to not need to edited within a transaction. It can be edited later with swap! and reset! commands.
Ok! I’m not gonna lie, this caching thing, I don’t get it at all. Not even a little bit…. wow.
Alright, agents make a little more sense. You can define a function and give it to an agent which is like a Thread. I’m familiar with Java, so I recognize Thread/sleep 5000 which puts that thread to sleep. Other than the weird syntax, this shouldn’t be too hard to implement. Futures are kind of cool, they seem to allow for asynchronous calls which wait for returns before executing. This seems like a mutex in other languages where you wait until the execution is finished and then continue.
Finishing up Day 3 there, it seems like multimethods allow Clojure to behave like JavaScript in that you can associate libraries of functions with a type. Thread states allow for variable binding that is Thread specific, I picture this like a local variable in function but with a Thread instead.
That finishes up Day 3 of Clojure in Seven Languages in Seven Weeks. I will continue to evaluate Clojure in the way we evaluated SML with looking at different aspects of the language.
Danny
Add a comment