Created
March 31, 2011 04:17
-
-
Save mecdemort/895803 to your computer and use it in GitHub Desktop.
mec.walk
This file contains hidden or 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
(ns mec.walk) | |
(defn f-walk [inner outer form] | |
(outer | |
(if (coll? form) | |
(into (empty form) (map inner form)) | |
form))) | |
(defn f-postwalk | |
"Depth first post-order traversal of form, apply successive fs at each level. | |
(f1 (map f2 [..]))" | |
[[f & fs] form] | |
(if (seq fs) | |
(f-walk (partial f-postwalk fs) f form) | |
(f form))) | |
(defn f-postwalk | |
"Depth first post-order traversal of form, apply successive fs at each level. | |
(f1 (map f2 [..]))" | |
[[f & fs] form] | |
(f | |
(if (and (seq fs) (coll? form)) | |
(into (empty form) (map (partial generic-walk fs) form)) | |
form))) | |
(defn f-prewalk | |
"Pre-order traversal of form, apply successive fs at each level. | |
(.. (map f2 (f1 [..])))" | |
[[f & fs] form] | |
(if (and (seq fs) (coll? form)) | |
(into (empty form) (map (partial generic-walk fs) (f form))) | |
(f form))) | |
(defn f-prewalk | |
"Pre-order traversal of form, apply successive fs at each level. | |
(.. (map f2 (f1 [..])))" | |
[[f & fs] form] | |
(if (seq fs) | |
(f-walk (partial f-prewalk fs) identity (f form)) | |
(f form))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment