First, if you end up using only one piece of a volatile state or several independent parts (regardless of how โit makes no sense to ask if it is consistent with anotherโ), why not go with Atoms and not with Ref ? This is a pretty significant reduction in overhead, which can make a difference if you make a lot of updates.
Secondly, saving the file name, scroll position, etc. in separate Refs (but not in Atoms) it is great if you carefully design your transactions (i.e. you need to mention all the relevant Refs, maybe some of them should be ensure d, etc. .. - basically the transaction should be fail if an inconsistent state occurs). Carefully designing such transactions can be a waste of effort if you manage the state of the GUI, most of which almost never change (besides the scroll position and the contents of the buffer, which can actually change often?) I mean, something is serious , since the answer should determine the final design). There are any number of scripts in which there are several objects of a reference type, preferably one, Iโm just not sure if one of them is to control the basic state of the GUI .:-)
Note that updating nested structures stored in objects of a reference type is very clean in Clojure, for example. (using Atom):
See also get-in and assoc-in .
source share