2
I’d like to have an accountant in memory. A variable that at any time I can add or subtract and when I want I access the current value of it.
How to do this in Chicago?
2
I’d like to have an accountant in memory. A variable that at any time I can add or subtract and when I want I access the current value of it.
How to do this in Chicago?
5
A simple way is to use one atom to maintain the current value:
(def cnt (atom 0))
(doseq [i (range 5) ]
(swap! cnt inc)
(println "value=" @cnt))
value= 1
value= 2
value= 3
value= 4
value= 5
Behold http://clojuredocs.org/clojure.core/atom and http://clojuredocs.org/clojure.core/swap!
Browser other questions tagged clojure
You are not signed in. Login or sign up in order to post.
Translate to English language
– rubStackOverflow
was exactly what I needed, vlw!
– guijob
I would like to point out, that Clojure, comes from the idea of immutable, ie, however much there is the function
atom, the use of it ends up escaping the scope.– Thomas Erich Pimentel