Skip to content

Instantly share code, notes, and snippets.

@jirkamarsik
Created December 19, 2012 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirkamarsik/4336670 to your computer and use it in GitHub Desktop.
Save jirkamarsik/4336670 to your computer and use it in GitHub Desktop.
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*)
record)]
(set! *fix-tree-adjunctions* (conj *fix-tree-adjunctions*
record)))))
(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*)
fixed-trees)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment