Created
December 19, 2012 13:32
-
-
Save jirkamarsik/4336670 to your computer and use it in GitHub Desktop.
Collecting traces from algorithms using dynamic Vars, first version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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