(html (head (title "sph-lib (sph tree)") (link (@ (rel "stylesheet") (type "text/css") (href "/css/sph.css"))) (meta (@ (name "viewport") (content "width=device-width,initial-scale=1"))) #f) (body () (div (@ (class top)) (nav (a (@ (href "/")) "start") ", " (a (@ (href "/feed.xml")) "feed")) "") (div (@ (class "middle")) (div (@ (class mtime) (title "last modification time of the current page")) "2023-04-05") (section (h1 "(sph tree)") (div (p "process tree-like list structures.") (p "part of " (a (@ (href "../../sph-lib.html")) "sph-lib")) ((section (@ (class "library-description")) (h1 "library description") (div (p "denoted") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "a representation using pairs where the first element denotes the nesting level and the second element is content")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(a b (c (d e)) f)-> ((0 . a) (1 . b) (2 . c) (3 . d) (3 . e) (0 . 4))")) (p "prefix-tree") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "first elements of lists interpreted as parent of tail elements. similar to scheme code for procedure application")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(a b (c (d e)) f)")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "example with nesting marked by indent")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "a")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "b")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "c")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "d")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "e")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "f")))) (section (@ (class "library-name")) (h1 "module name") (p "(sph tree)")) (section (@ (class "library-exports")) (h1 "exported bindings") (div (div (@ (class "doc-bindings")) (div (@ (id "doc-b-" "denoted-tree->prefix-tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "denoted-tree->prefix-tree") " " (span (@ (class "first-sig")) "a [depth-start] ->")) (div (@ (class "rest-sig")) (div "list [integer] -> list")) (div (@ (class "description")) (("convert a tree representation like this ((0 a) (1 b) (2 c) (1 d)) to this (a (b c) d)." (br) "cases like ((0 a) (3 b) (0 c)) are converted to (a ((b)) c)")))) (div (@ (id "doc-b-" "denoted-tree->tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "denoted-tree->tree") " " (span (@ (class "first-sig")) "a [depth-start] ->")) (div (@ (class "rest-sig")) (div "list:((integer any ...) ...) [integer] -> list")) (div (@ (class "description")) (("convert a tree representation like this ((0 a) (1 b) (2 c) (1 d)) to this (a (b (c) d))")))) (div (@ (id "doc-b-" "denoted-tree->tree-inner") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "denoted-tree->tree-inner") " " (span (@ (class "first-sig")) "a depth-start r-2 r update-r ...")) "" "") (div (@ (id "doc-b-" "denoted-tree-adjust-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "denoted-tree-adjust-depth") " " (span (@ (class "first-sig")) "a operator arguments ... ->")) (div (@ (class "rest-sig")) (div "procedure list integer -> list")) (div (@ (class "description")) (("map the nesting-depth of each element with operator and arguments." (br) "the lowest possible depth is bounded to zero." (br) "example:" (br) "(denoted-tree-adjust-depth a + 1)")))) (div (@ (id "doc-b-" "denoted-tree-minimise-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "denoted-tree-minimise-depth") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "procedure list integer -> list")) (div (@ (class "description")) (("decrease nesting-depth for all element until at least one element has a nesting-depth of zero")))) (div (@ (id "doc-b-" "prefix-tree->denoted-tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree->denoted-tree") " " (span (@ (class "first-sig")) "a initial-depth ... ->")) (div (@ (class "rest-sig")) (div "list [integer] -> list") (div "like tree ->")) (div (@ (class "description")) (("denoted-tree but the nesting-depth number corresponds to prefix-tree interpretation. example" (br) "(a b (c (d e)) f) -> ((0 . a) (1 . b) (2 . c) (3 . d) (3 . e) (0 . 4))")))) (div (@ (id "doc-b-" "prefix-tree->infix-tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree->infix-tree") " " (span (@ (class "first-sig")) "a [prefix->infix] ->")) (div (@ (class "rest-sig")) (div "list [procedure:{any -> any}] -> list")) (div (@ (class "description")) (("converts list structures like (or a b (and c d)) to (a or b or (c and d))" (br) "the optional procedure translates prefixes")))) (div (@ (id "doc-b-" "prefix-tree->paths") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree->paths") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "list -> (string ...)")) (div (@ (class "description")) (("regard tree as a nested list representation of a filesystem file and directory structure" (br) "and return a flat list of filesystem path strings." (br) "example:" (br) "(prefix-tree->paths (list \\\"/usr\\\" (list \\\"bin\\\" (list \\\"share\\\" \\\"guile\\\") \\\"include\\\") \\\"/var\\\"))" (br) "creates" (br) "(list" (br) " \\\"/usr/bin\\\"" (br) " \\\"/usr/share/guile\\\"" (br) " \\\"/usr/include\\\"" (br) " \\\"/var\\\")")))) (div (@ (id "doc-b-" "prefix-tree->relations") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree->relations") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "list -> (pair ...)")) (div (@ (class "description")) (("create a list of all individual relations between prefix and tail elements or tail element prefixes." (br) "example:" (br) "((a (b c (d e)))) -> ((a . b) (b . c) (b . d) (d . e))")))) (div (@ (id "doc-b-" "prefix-tree-context-match") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-context-match") " " (span (@ (class "first-sig")) "a pattern ->")) (div (@ (class "rest-sig")) (div "list list -> boolean")) (div (@ (class "description")) (("true if pattern exists in prefix-tree with the same tree interpretation as prefix-tree-context-produce." (br) "example: (a b (d c)) contains patterns (a d c) and (a b) and (a d)")))) (div (@ (id "doc-b-" "prefix-tree-map") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-map") " " (span (@ (class "first-sig")) "f a ->")) "" (div (@ (class "description")) (("{any:prefix list:tail} list -> list" (br) "map only lists, split into prefix and tail")))) (div (@ (id "doc-b-" "prefix-tree-map-c") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-map-c") " " (span (@ (class "first-sig")) "f continue& a ->")) "" (div (@ (class "description")) (("procedure:{prefix tail} procedure:{list procedure:f procedure:continue:{list ->}} list -> list" (br) "maps over only the lists, split into prefix and tail." (br) "the procedure continue& gets a procedure argument that when called continues the iteration. if it is not called," (br) "the iteration stops and the result of continue& is the main result")))) (div (@ (id "doc-b-" "prefix-tree-map-c-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-map-c-depth") " " (span (@ (class "first-sig")) "f continue a [inc depth-init] ->")) "" (div (@ (class "description")) (("{any:prefix list:tail any} {list procedure:f {list ->} any}:continue list [{integer -> integer}] -> list" (br) "like prefix-tree-map-c but with additional arguments for the current nesting-depth")))) (div (@ (id "doc-b-" "prefix-tree-map-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-map-depth") " " (span (@ (class "first-sig")) "f a [initial-depth] ->")) (div (@ (class "rest-sig")) (div "{any:prefix list:tail integer:depth -> any} list [integer] -> list")) (div (@ (class "description")) (("like prefix-tree-map but with an additional argument for the current nesting-depth")))) (div (@ (id "doc-b-" "prefix-tree-map-depth-flat") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-map-depth-flat") " " (span (@ (class "first-sig")) "proc a initial-depth ... ->")) (div (@ (class "rest-sig")) (div "{integer any -> any} list [integer] -> (any ...)") (div "like tree ->")) (div (@ (class "description")) (("denoted-tree-->flat but the nesting-depth number corresponds to prefix-tree interpretation")))) (div (@ (id "doc-b-" "prefix-tree-map-with-context") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-map-with-context") " " (span (@ (class "first-sig")) "f a ->")) "" (div (@ (class "description")) (("{any list:upper-prefixes} list -> list" (br) "like (prefix-tree-map) but with an additional argument for parent prefixes")))) (div (@ (id "doc-b-" "prefix-tree-produce") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-produce") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "{any ... -> any} list:prefix-tree -> list")) (div (@ (class "description")) (("calls f for each combination of prefix and tail")))) (div (@ (id "doc-b-" "prefix-tree-produce-with-context") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-produce-with-context") " " (span (@ (class "first-sig")) "f a [ignore-prefixes] ->")) (div (@ (class "rest-sig")) (div "{element context -> any} list -> list")) (div (@ (class "description")) (("context is a list containing nested-list prefixes in bottom-to-top order." (br) "for example (a (d e f) k (g h i) j) leads to f called with each of the following arguments:" (br) "(d (a)), (e (d a)), (f (d a)),(k (a)), (g (a)), (h (g a)), (i (g a)), (j (a))" (br) "ignore-prefixes ignores lists that are themselves prefixes")))) (div (@ (id "doc-b-" "prefix-tree-produce-with-context-mm") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-produce-with-context-mm") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure:{any list -> any} list -> list")) (div (@ (class "description")) (("like prefix-tree-produce-with-context but lists can be used as list prefixes for many-to-many relations")))) (div (@ (id "doc-b-" "prefix-tree-product") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-product") " " (span (@ (class "first-sig")) "a [ignore-prefixes?] ->")) "" "") (div (@ (id "doc-b-" "prefix-tree-product-mm") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-product-mm") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "prefix-tree-replace-prefix") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "prefix-tree-replace-prefix") " " (span (@ (class "first-sig")) "a replacements ->")) (div (@ (class "rest-sig")) (div "list ((to-replace . replacement) ...) -> list")) (div (@ (class "description")) (("replace all list prefixes, the first element of a list, in tree based on the given replacements structure")))) (div (@ (id "doc-b-" "sph-tree-description") (class "doc-b")) (div (span (@ (class "type")) "variable") ": " (span (@ (class "name")) "sph-tree-description")) "" "") (div (@ (id "doc-b-" "tree->denoted-tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree->denoted-tree") " " (span (@ (class "first-sig")) "a initial-depth ... ->")) (div (@ (class "rest-sig")) (div "list [integer] -> list")) (div (@ (class "description")) (("convert a tree to an association list where each element is a list having a nesting-depth number" (br) "as the first element. similar to this is the usage of indentation for nesting depth." (br) "(a b (c (d e)) f) -> ((0 . a) (0 . b) (1 . c) (2 . d) (2 . e) (0 . f))")))) (div (@ (id "doc-b-" "tree-any") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-any") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure list -> false/any")) (div (@ (class "description")) (("call f with each tree element list or leaf from top to bottom and return the first true result of f." (br) "can be used to extract single elements from tree. aliased as tree-any and tree-extract")))) (div (@ (id "doc-b-" "tree-contains-all?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-contains-all?") " " (span (@ (class "first-sig")) "a equal? search-values ... ->")) (div (@ (class "rest-sig")) (div "list {any any -> boolean} any ... -> boolean")) (div (@ (class "description")) (("like tree-contains? but true only if every of the search-values has been found")))) (div (@ (id "doc-b-" "tree-contains-some-not?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-contains-some-not?") " " (span (@ (class "first-sig")) "a equal? search-values ... ->")) (div (@ (class "rest-sig")) (div "list {any any -> boolean} any ... -> boolean")) (div (@ (class "description")) (("like tree-contains? but true only if any of the search-values is not contained")))) (div (@ (id "doc-b-" "tree-contains-some?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-contains-some?") " " (span (@ (class "first-sig")) "a equal? search-values ... ->")) (div (@ (class "rest-sig")) (div "list {any any -> boolean} any ... -> boolean")) (div (@ (class "description")) (("like tree-contains? and true if any of the search-values is found")))) (div (@ (id "doc-b-" "tree-contains?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-contains?") " " (span (@ (class "first-sig")) "a search-value [equal?] ->")) (div (@ (class "rest-sig")) (div "list any [procedure:{any any -> boolean}] -> boolean")) (div (@ (class "description")) (("compares all list and non-list elements with search-value and returns true on a match")))) (div (@ (id "doc-b-" "tree-each") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-each") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure:{any ->} list ->")) (div (@ (class "description")) (("call f for every element in tree, lists and non-lists." (br) "list elements left to right, nested lists bottom to top." (br) "tree-for-each")))) (div (@ (id "doc-b-" "tree-each-leaf") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-each-leaf") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure:{any ->} list ->")) (div (@ (class "description")) (("call f for each non-list element in tree")))) (div (@ (id "doc-b-" "tree-every") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-every") " " (span (@ (class "first-sig")) "f a ->")) "" "") (div (@ (id "doc-b-" "tree-extract") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-extract") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure list -> false/any")) (div (@ (class "description")) (("call f with each tree element list or leaf from top to bottom and return the first true result of f." (br) "can be used to extract single elements from tree. aliased as tree-any and tree-extract")))) (div (@ (id "doc-b-" "tree-filter") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-filter") " " (span (@ (class "first-sig")) "predicate a ->")) (div (@ (class "rest-sig")) (div "procedure:{element -> any/boolean} list -> list")) (div (@ (class "description")) (("call predicate for each non-list and list element in tree and" (br) "only keep the elements for which predicate returned true." (br) "elements left to right, nested lists bottom to top." (br) "example" (br) " (tree-filter (l (a) (or (list? a) (even? a))) (q (1 2 3 (4 5 (6 7) (8 9 10)))))" (br) " ->" (br) " (2 (4 (6) (8 10)))")))) (div (@ (id "doc-b-" "tree-filter-flat") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-filter-flat") " " (span (@ (class "first-sig")) "predicate a ->")) (div (@ (class "rest-sig")) (div "procedure:{any -> boolean/any} list -> list")) (div (@ (class "description")) (("results in a flat list of all list and non-lists elements of tree" (br) "for which predicate returned true")))) (div (@ (id "doc-b-" "tree-filter-leafs") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-filter-leafs") " " (span (@ (class "first-sig")) "predicate a ->")) "" (div (@ (class "description")) (("like tree-filter but calls predicate only for non-list elements")))) (div (@ (id "doc-b-" "tree-filter-lists") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-filter-lists") " " (span (@ (class "first-sig")) "predicate a ->")) "" (div (@ (class "description")) (("like tree-filter but calls predicate only for list elements." (br) "example - keep only lists with more than 3 elements" (br) " (tree-filter-lists (l (a) (< 3 (length a))) (q (1 2 3 (4 5 (6 7) (8 9 10)))))" (br) " ->" (br) " (1 2 3)")))) (div (@ (id "doc-b-" "tree-find") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-find") " " (span (@ (class "first-sig")) "predicate a ->")) (div (@ (class "rest-sig")) (div "procedure:{element -> any/boolean} list -> any")) (div (@ (class "description")) (("find a sub-tree that contains an element that matches predicate")))) (div (@ (id "doc-b-" "tree-finder") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-finder") " " (span (@ (class "first-sig")) "find f a ->")) (div (@ (class "rest-sig")) (div "procedure:{predicate list ... -> any} procedure:{element -> any/boolean} list -> any")) (div (@ (class "description")) (("call f with each tree list and leaf from top to bottom and return true results of f")))) (div (@ (id "doc-b-" "tree-fold") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-fold") " " (span (@ (class "first-sig")) "p r t ->")) (div (@ (class "rest-sig")) (div "procedure:{any:element any:result -> any:result} any:result list:tree -> any")) (div (@ (class "description")) (("fold over all lists and non-list elements in tree" (br) "elements from left to right, nested lists bottom to top." (br) "lists passed to f will be fold results from list elements that have already been processed." (br) "see tree-fold-right for examples")))) (div (@ (id "doc-b-" "tree-fold-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-fold-depth") " " (span (@ (class "first-sig")) "p r t [n inc] ->")) "" (div (@ (class "description")) (("procedure:{element result integer:depth} any tree [integer:depth procedure:{integer -> integer}] -> any" (br) "like tree-fold but keeps track of the current nesting depth")))) (div (@ (id "doc-b-" "tree-fold-right") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-fold-right") " " (span (@ (class "first-sig")) "p r t ->")) (div (@ (class "rest-sig")) (div "procedure:{any:element any:result -> any:result} any:result list:tree -> any:result")) (div (@ (class "description")) (("fold over all list and non-list elements in tree." (br) "elements from left to right, nested lists bottom to top" (br) "example 1" (br) " (tree-fold-right" (br) " (l (a r) (pair a r))" (br) " (list)" (br) " (q (1 2 3 (4 5 (6 7) (8 9 10)))))" (br) " ->" (br) " (q (1 2 3 (4 5 (6 7) (8 9 10))))" (br) "example 2" (br) " (tree-fold-right" (br) " (l (a r) (if (list? a) a (if (even? a) (pair a r) r)))" (br) " (list) (q (1 2 3 (4 5 (6 7) (8 9 10)))))" (br) " ->" (br) " (q (1 2 3 (4 5 (6 7) (8 9 10))))")))) (div (@ (id "doc-b-" "tree-fold-right-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-fold-right-depth") " " (span (@ (class "first-sig")) "f r t [depth inc] ->")) (div (@ (class "rest-sig")) (div "procedure:{any:element any:result -> any:result} any:result list:tree -> any")) (div (@ (class "description")) (("fold over all list and non-list elements in tree." (br) "elements from left to right, nested lists bottom to top")))) (div (@ (id "doc-b-" "tree-map") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure:{any -> any} list -> list")) (div (@ (class "description")) (("maps elements left to right and nested lists bottom to top." (br) "not map the topmost tree structure itself.")))) (div (@ (id "doc-b-" "tree-map-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-depth") " " (span (@ (class "first-sig")) "f a [initial-depth] ->")) "" (div (@ (class "description")) (("procedure:{any:element integer:depth} list [integer] -> list" (br) "like tree-map but also passes a number for the current nesting depth to f")))) (div (@ (id "doc-b-" "tree-map-depth-flat") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-depth-flat") " " (span (@ (class "first-sig")) "f a initial-depth ... ->")) (div (@ (class "rest-sig")) (div "procedure:{integer:depth any:element -> any:result-element} list [integer] -> (any ...)")) (div (@ (class "description")) (("map elements of tree to a flat list. apply f with a number" (br) "stating how deeply the element is nested in other lists and the current element")))) (div (@ (id "doc-b-" "tree-map-leafs") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-leafs") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "procedure:{any -> any} list -> list")) (div (@ (class "description")) (("call f only with non-list elements, all other elements are kept")))) (div (@ (id "doc-b-" "tree-map-lists") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-lists") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "{list -> any} list -> list")) (div (@ (class "description")) (("like tree-map but pass only the lists in tree to f, skipping and keeping non-list elements. bottom-to-top")))) (div (@ (id "doc-b-" "tree-map-lists-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-lists-depth") " " (span (@ (class "first-sig")) "f a [depth-init map-depth] ->")) (div (@ (class "rest-sig")) (div "{list integer:depth -> any} list [integer {integer -> integer:next-depth}] -> list")) (div (@ (class "description")) (("like tree-map-lists with additional arguments for the current nesting depth")))) (div (@ (id "doc-b-" "tree-map-lists-self") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-lists-self") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "{list -> any} list -> list")) (div (@ (class "description")) (("like tree-map-and-self but calls f only for list elements")))) (div (@ (id "doc-b-" "tree-map-self") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-self") " " (span (@ (class "first-sig")) "f a ->")) (div (@ (class "rest-sig")) (div "{any -> any} list -> list")) (div (@ (class "description")) (("like tree-map-lists but also map the given list itself")))) (div (@ (id "doc-b-" "tree-map-with-state") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-map-with-state") " " (span (@ (class "first-sig")) "f a init ... ->")) (div (@ (class "rest-sig")) (div "{any any:custom-state-value ... -> list:custom-state-values} -> (list:mapped-elements any:custom-state-value ...)")) (div (@ (class "description")) (("like tree-map but can carry and update a number of custom values per call, similar to fold-multiple")))) (div (@ (id "doc-b-" "tree-mapper") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-mapper") " " (span (@ (class "first-sig")) "map f a ->")) (div (@ (class "rest-sig")) (div "procedure:{procedure list ... -> list} procedure:{element -> new-element} list -> list")) (div (@ (class "description")) (("map over lists and sub-lists using the given map procedure, which needs to have the same" (br) "signature as \\\"map\\\"." (br) "maps from bottom to top")))) (div (@ (id "doc-b-" "tree-mapper-produce") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-mapper-produce") " " (span (@ (class "first-sig")) "map f a b ->")) (div (@ (class "rest-sig")) (div "procedure:{f list:elements -> any} procedure:{any:element-a any:element-b -> any}:f list list -> any")) (div (@ (class "description")) (("call f with each ordered combination between elements of two lists with a" (br) "map procedure that is called nested like" (br) "(each (lambda (a) (each (lambda (b) (f a b)) b)) a)")))) (div (@ (id "doc-b-" "tree-mapper-top") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-mapper-top") " " (span (@ (class "first-sig")) "map f a ->")) (div (@ (class "rest-sig")) (div "procedure:{procedure list ... -> list} procedure:{element -> new-element} list -> list")) (div (@ (class "description")) (("maps from top to bottom." (br) "list results of f will be entered for further mapping." (br) "this procedure is used to map sub-lists before eventually" (br) "mapping their elements if the map result is a list")))) (div (@ (id "doc-b-" "tree-produce") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-produce") " " (span (@ (class "first-sig")) "f a b ->")) (div (@ (class "rest-sig")) (div "procedure:{any any -> any} list list -> any")) (div (@ (class "description")) (("apply f with every possible ordered combination of list and non-list elements of trees." (br) "traverses like tree-map")))) (div (@ (id "doc-b-" "tree-produce-lists") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-produce-lists") " " (span (@ (class "first-sig")) "f a b ->")) "" (div (@ (class "description")) (("like tree-produce only for list elements")))) (div (@ (id "doc-b-" "tree-produce-lists-depth") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-produce-lists-depth") " " (span (@ (class "first-sig")) "f a b [inc depth-init] ->")) "" (div (@ (class "description")) (("{any:element-a any:element-b integer:depth-a integer:depth-b} list:list-a list:list-b [{integer -> integer} integer] -> list")))) (div (@ (id "doc-b-" "tree-replace-at-once") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-replace-at-once") " " (span (@ (class "first-sig")) "predicate f a ->")) (div (@ (class "rest-sig")) (div "procedure:{element -> boolean} procedure:{list:matched-elements -> list} list -> list")) (div (@ (class "description")) (("searches through tree recursively, collecting all elements (including lists) that match collect-proc, then calls" (br) "f with a list of matched elements. the result of f must of length zero (no replacement) or matched-element-count (replaces all matches)." (br) "results in the tree with the matched elements are replaced in order by the result elements from calling f")))) (div (@ (id "doc-b-" "tree-replace-by-list") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-replace-by-list") " " (span (@ (class "first-sig")) "a replace? replacements ->")) (div (@ (class "rest-sig")) (div "list {any -> boolean} (any ...) -> list")) (div (@ (class "description")) (("replace each non-list element in tree that matches replace? with the next element from replacements." (br) "it is an error if there are more replacements than matches")))) (div (@ (id "doc-b-" "tree-splice") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-splice") " " (span (@ (class "first-sig")) "predicate a ->")) (div (@ (class "rest-sig")) (div "prodecure:{element -> boolean/any} list -> list")) (div (@ (class "description")) (("merge nested lists with that match predicate with their parent list." (br) "example" (br) " (tree-splice (l (a) (= 3 (length a))) (q (1 2 3 (4 5 (6 7) (8 9 10)))))" (br) " ->" (br) " (1 2 3 (4 5 (6 7) 8 9 10))")))) (div (@ (id "doc-b-" "tree-transform") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-transform") " " (span (@ (class "first-sig")) "a descend ascend terminal ->")) (div (@ (class "rest-sig")) (div "list procedure procedure procedure -> any")) (div (@ (class "description")) (("descend :: any:element procedure:recurse-descend -> (any:result-element boolean:continue?)" (br) "ascend :: any:element -> any:result-element" (br) "terminal :: any:element -> any:result-element" (br) "map/transform list and sub-lists first top to bottom, calling \\\"descend\\\" for each sub-list," (br) "then bottom to top, calling \\\"ascend\\\" for lists and \\\"terminal\\\" for non-lists/leafs." (br) "descend should return a list of two values: the first for the result and the second a boolean indicating if the result" (br) "should be passed to ascend and terminal (true) or if that should be skipped (false)." (br) "example use cases:" (br) "* compile s-expression list trees into string output languages by mapping all expressions and sub-expressions to strings" (br) "* replace some lists in a tree")))) (div (@ (id "doc-b-" "tree-transform*") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-transform*") " " (span (@ (class "first-sig")) "a descend ascend terminal states ... ->")) (div (@ (class "rest-sig")) (div "list procedure procedure procedure any ... -> any")) (div (@ (class "description")) (("descend :: any:element procedure:recurse-descend any:state ... -> (any:result-element boolean:continue? any:state ...)" (br) "ascend :: any:element any:state ... -> (any:result-element any:state ...)" (br) "terminal :: any:element any:state ... -> (any:result-element any:state ...)" (br) "like tree-transform but also takes, passes and updates caller specified values")))) (div (@ (id "doc-b-" "tree-transform-ascend") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-transform-ascend") " " (span (@ (class "first-sig")) "rest leaf-list recurse-descend ascend terminal states ->")) "" "") (div (@ (id "doc-b-" "tree-transform-descend-identity") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "tree-transform-descend-identity") " " (span (@ (class "first-sig")) "a ... ->")) (div (@ (class "rest-sig")) (div "any ... -> (#f #t)")) (div (@ (class "description")) (("a tree-transform descend procedure that does not do anything"))))))))))) ()))