Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Collecting traces from algorithms using dynamic Vars, first version.
(def ^:dynamic *fix-tree-adjunctions*)
(def ^:dynamic *fix-tree-current-name*)
(defn record-adjunct
"Records an adjunction performed within fix-tree."
[phrase adjunct]
(if (thread-bound? #'*fix-tree-adjunctions*)
(let [record {:phrase phrase
:adjunct adjunct}
record (if (thread-bound? #'*fix-tree-current-name*)
(assoc record :name *fix-tree-current-name*)
(set! *fix-tree-adjunctions* (conj *fix-tree-adjunctions*
(def fixed-trees
"A map from tree filenames to their fixed versions."
(binding [*fix-tree-adjunctions* []]
(let [fixed-trees (into {} (for [[name tree] trees]
(binding [*fix-tree-current-name* name]
[name (fix-tree tree)])))]
; As a side effect of transforming all our trees, I have also
; recorded the adjunctions performed in the process, so I save
; them too.
(def adjunctions *fix-tree-adjunctions*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment