(walk ast pre post)
(walk ast pre post reversed?)
Walk the ast applying `pre` when entering the nodes, and `post` when exiting.
Both functions must return a valid node since the returned value will replace
the node in the AST which was given as input to the function.
If reversed? is not-nil, `pre` and `post` will be applied starting from the last
children of the AST node to the first one.
Short-circuits on reduced.
Source
(defn walk
"Walk the ast applying `pre` when entering the nodes, and `post` when exiting.
Both functions must return a valid node since the returned value will replace
the node in the AST which was given as input to the function.
If reversed? is not-nil, `pre` and `post` will be applied starting from the last
children of the AST node to the first one.
Short-circuits on reduced."
([ast pre post]
(walk ast pre post false))
([ast pre post reversed?]
(unreduced
((fn walk [ast pre post reversed?]
(let [walk #(walk % pre post reversed?)]
(if (reduced? ast)
ast
(let [ret (update-children-reduced (pre ast) walk reversed?)]
(if (reduced? ret)
ret
(post ret))))))
ast pre post reversed?))))