Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created February 12, 2012 08:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/1807340 to your computer and use it in GitHub Desktop.
Save amalloy/1807340 to your computer and use it in GitHub Desktop.
(defn vec->tree [calls]
(-> (reduce (fn [tree [op was-ret?]]
(if was-ret?
(-> tree
(z/append-child op)
(z/up))
(-> tree
(z/append-child [op])
(z/down)
(z/rightmost))))
(z/vector-zip [])
calls)
(z/root)))
user> (vec->tree '[[(+ (* 2 3) (- 5 2)) nil]
[(* 2 3) nil]
[6 true]
[(- 5 2) nil]
[3 true]
[4 true]])
[[(+ (* 2 3) (- 5 2))
[(* 2 3)
6]
[(- 5 2)
3]
4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment