Skip to content

clojure.walk/postwalk

View this page on ClojureDocs

Type: function Added: Clojure 1.1 Examples: 6 Runnable: 1
([f form])

Performs a depth-first, post-order traversal of form. Calls f on each sub-form, uses f's return value in place of the original. Recognizes all Clojure data structures. Consumes seqs as with doall.

Examples

by sunil.nandihalli on . May have evaluation errors.
by boxie on . May have evaluation errors.
by wmatson on . May have evaluation errors.
by cljlc on . May have evaluation errors.
by burinc on
by tomdl89 on . May have evaluation errors.

Note by pesterhazy

As of 1.9.0, postwalk passes the k/v pairs of a map to f not, as one might expect, as type clojure.lang.MapEntry but as clojure.lang.PersistentVector (JIRA). As a result, f cannot distinguish k/v pairs from other two-element vectors.

Note by finalfantasia

Alex Miller's article "Tree visitors in Clojure" might be helpful in understanding general tree traversal and the usage of clojure.walk/postwalk.

Note by leo-ppp

As of 1.9.0, postwalk passes the k/v pairs of a map to f not, as one might expect, as type clojure.lang.MapEntry but as clojure.lang.PersistentVector (JIRA). As a result, f cannot distinguish k/v pairs from other two-element vectors.

This was fixed in 1.10.0, and one can use (map-entry? v) to distinguish a k/v pair from a vector when walking.

Note by jeff303

Updated link to "Tree visitors in Clojure", mentioned above (PDF):

https://insideclojure.org/images/j-treevisit-pdf.pdf

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.