Accessing the history of a `ref` in Clojure
https://softwareengineering.stackexchange.com/questions/188239
Question
The documentation for ref shows a :max-history option and states that "refs accumulate history dynamically as needed to deal with read demands." I can see that there is history at the REPL, but I don't see how to find previous values of a ref:
user=> (def the-world (ref "hello" :min-history 10))
#'user/the-world
user=> (do
(dosync (ref-set the-world "better"))
@the-world)
"better"
user=> (let [exclamator (fn [x] (str x "!"))]
(dosync
(alter the-world exclamator)
(alter the-world exclamator)
(alter the-world exclamator))
@the-world)
"better!!!"
user=> (ref-history-count the-world)
2
Presumably the-world has had the values "hello", "better", and "better!!!". How do I access that history?
If it is not possible to access that history, is there a datatype that keeps a history of its values that can be queried afterwards? Or is that why the datomic database was created?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange