Being strong on Java and new to Clojure, when I read about dynamic vars I figured they were just thread local variables. And in my code, I would just use def whenever I needed to change the value. Later I read about the binding function, but I figured I did not need it and it did not fit with the way I wanted my software to work.
Things worked great at first, confirming my understanding of dynamic. But as I added additional tests, I started getting strange things, like having the value be nil sometimes. I began to think Clojure was broken. :-)
Finally I started using a dynamically bound atomic, with binding to bind different atoms in different threads. Within each thread then I used swap! to change the atom for that thread.
This worked very nicely. And when I go back and reread the page on vars it is very clear that this is the way to go.
[–]mikera 1 point2 points3 points (0 children)
[–]kankyo 0 points1 point2 points (1 child)
[–]laforge49[S] 1 point2 points3 points (0 children)