Namespace: joker.walk
v1.0Contents
Summary
Defines a generic tree walker for Clojure data structures.
Takes any data structure (list, vector, map, set, seq), calls
a function on every element, and uses the return value of the
function in place of the original. This makes it fairly easy
to write recursive search-and-replace functions, as shown in
the examples.
Note: "walk" supports all Clojure data structures EXCEPT maps
created with sorted-map-by. There is no (obvious) way to retrieve
the sorting function.
Index
- keywordize-keys
- macroexpand-all
- postwalk
- postwalk-demo
- postwalk-replace
- prewalk
- prewalk-demo
- prewalk-replace
- stringify-keys
- walk
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
keywordize-keys
Function v1.0(keywordize-keys m)
Recursively transforms all map keys from strings to keywords.
source -
macroexpand-all
Function v1.0(macroexpand-all form)
Recursively performs all possible macroexpansions in form.
source -
postwalk
Function v1.0(postwalk f form)
Performs a depth-first, post-order traversal of form. Calls f on
source
each sub-form, uses f's return value in place of the original.
Recognizes all Clojure data structures. Consumes seqs as with doall. -
postwalk-demo
Function v1.0(postwalk-demo form)
Demonstrates the behavior of postwalk by printing each form as it is
source
walked. Returns form. -
postwalk-replace
Function v1.0(postwalk-replace smap form)
Recursively transforms form by replacing keys in smap with their
source
values. Like clojure/replace but works on any data structure. Does
replacement at the leaves of the tree first. -
prewalk
Function v1.0(prewalk f form)
Like postwalk, but does pre-order traversal.
source -
prewalk-demo
Function v1.0(prewalk-demo form)
Demonstrates the behavior of prewalk by printing each form as it is
source
walked. Returns form. -
prewalk-replace
Function v1.0(prewalk-replace smap form)
Recursively transforms form by replacing keys in smap with their
source
values. Like clojure/replace but works on any data structure. Does
replacement at the root of the tree first. -
stringify-keys
Function v1.0(stringify-keys m)
Recursively transforms all map keys from keywords to strings.
source -
walk
Function v1.0(walk inner outer form)
Traverses form, an arbitrary data structure. inner and outer are
source
functions. Applies inner to each element of form, building up a
data structure of the same type, then applies outer to the result.
Recognizes all Clojure data structures. Consumes seqs as with doall.