refs

dealing cards in Clojure

I am trying to write a Spider Solitaire player as an exercise in learning Clojure. I am trying to figure out how to deal the cards. I have created (with the help of stackoverflow), a shuffled sequence of 104 cards from two standard decks. Each card is represented as a (defstruct card :rank :suit :face-up) The tableau for Spider will ...

Best Practice for globals in clojure, (refs vs alter-var-root)?

I've found myself using the following idiom lately in clojure code. (def *some-global-var* (ref {})) (defn get-global-var [] @*global-var*) (defn update-global-var [val] (dosync (ref-set *global-var* val))) Most of the time this isn't even multi-threaded code that might need the transactional semantics that refs give you. It jus...

The more threads that changes the Clojure's ref are, the more does the rate of retries per threads rise?

I worry about this a little. Imagine the simplest version controll way that programmers just copy all directory from the master repository and after changing a file do reversely if the master repository is still the same. If it has been changed by another, they must try again. When the number of programmers increases, it is natural tha...