summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
Diffstat (limited to 'txr.1')
-rw-r--r--txr.115
1 files changed, 15 insertions, 0 deletions
diff --git a/txr.1 b/txr.1
index 031d7d9e..06cb8305 100644
--- a/txr.1
+++ b/txr.1
@@ -32462,6 +32462,21 @@ macro for deleting a place.
;; add function:
(build [mapdo add (range 1 3)]) -> (1 2 3)
+
+ ;; breadth-first traversal of nested list;
+ (defun bf-map (tree visit-fn)
+ (buildn
+ (add tree)
+ (whilet ((item (del)))
+ (if (atom item)
+ [visit-fn item]
+ (each ((el item))
+ (add el))))))
+
+ (let (flat)
+ (bf-map '(1 (2 (3 4 (5))) ((6 7) 8)) (do push @1 flat))
+ (nreverse flat))
+ -> (1 2 8 3 4 6 7 5)
.brev
.SS* Permutations and Combinations