;ELC ;;; Compiled ;;; in Emacs version 28.0.50 ;;; with all optimizations. (byte-code "\300\301!\210\300\302!\207" [require map cl-lib] 2) #@296 Using INNER and OUTER, traverse FORM, an arbitrary data structure. INNER and OUTER are functions. Apply INNER to each element of FORM, building up a data structure of the same type, then apply OUTER to the result. Recognize cons, lists, alists, vectors and hash tables. (fn INNER OUTER FORM) (defalias 'treepy-walk #[771 "\211<\203\211A\203\211A:\204@!A!B!\207\211<\203(\300\"!\207\301!\2039\302\303\300\"\"!\207\304!\203J\305\306\307\"\"!\207!\207" [mapcar vectorp apply vector hash-table-p map-apply make-closure #[514 "\300B!\207" [V0] 5 "\n\n(fn K V)"]] 9 (#$ . 152)]) #@209 Perform a depth-first, post-order traversal of F applied to FORM. Call F on each sub-form, use F's return value in place of the original. Recognize cons, lists, alists, vectors and hash tables. (fn F FORM) (defalias 'treepy-postwalk #[514 "\300\301\302\"#\207" [treepy-walk apply-partially treepy-postwalk] 6 (#$ . 766)]) #@103 Perform a depth-first, pre-order traversal of F applied to FORM. Like `treepy-postwalk'. (fn F FORM) (defalias 'treepy-prewalk #[514 "\300\301\302\"\303!#\207" [treepy-walk apply-partially treepy-prewalk identity] 7 (#$ . 1100)]) #@112 Demonstrate the behavior of `treepy-postwalk' for FORM. Return a list of each form as it is walked. (fn FORM) (defalias 'treepy-postwalk-demo #[257 "\300C\301\302\303\"\"\210\304\242!\207" [nil treepy-postwalk make-closure #[257 "\300\300\242B\240\210\207" [V0] 4 "\n\n(fn X)"] reverse] 6 (#$ . 1341)]) #@111 Demonstrate the behavior of `treepy-prewalk' for FORM. Return a list of each form as it is walked. (fn FORM) (defalias 'treepy-prewalk-demo #[257 "\300C\301\302\303\"\"\210\304\242!\207" [nil treepy-prewalk make-closure #[257 "\300\300\242B\240\210\207" [V0] 4 "\n\n(fn X)"] reverse] 6 (#$ . 1656)]) #@284 Use SMAP to transform FORM by doing replacing operations. Recursively replace in FORM keys in SMAP with their values. Does replacement at the leaves of the tree first. The optional TESTFN parameter is the function to be used by `map-contains-key'. (fn SMAP FORM &optional TESTFN) (defalias 'treepy-postwalk-replace #[770 "\300\301\302#\"\207" [treepy-postwalk make-closure #[257 "\302\300\301#\203 \303\300\"\207\207" [V0 V1 map-contains-key map-elt] 5 "\n\n(fn X)"]] 8 (#$ . 1968)]) #@282 Use SMAP to transform FORM by doing replacing operations. Recursively replace in FORM keys in SMAP with their values. Does replacement at the root of the tree first. The optional TESTFN parameter is the function to be used by `map-contains-key'. (fn SMAP FORM &optional TESTFN) (defalias 'treepy-prewalk-replace #[770 "\300\301\302#\"\207" [treepy-prewalk make-closure #[257 "\302\300\301#\203 \303\300\"\207\207" [V0 V1 map-contains-key map-elt] 5 "\n\n(fn X)"]] 8 (#$ . 2468)]) #@112 Return context for this LOC. If KEY is given, only return this key's value in context. (fn LOC &optional KEY) (defalias 'treepy--context #[513 "@A\211\203\203\300\"\207\207" [map-elt] 6 (#$ . 2964)]) #@60 Assoc in CONTEXT a key K with a value V. (fn CONTEXT K V) (defalias 'treepy--context-assoc-1 #[771 "\300\"\203\301\302\303#\"\207BB\207" [map-contains-key mapcar make-closure #[257 "\211@\300\232\203 \300\301B\207\207" [V0 V1] 3 "\n\n(fn ENTRY)"]] 8 (#$ . 3179)]) #@73 Immutable map association in CONTEXT using KVS. (fn CONTEXT &rest KVS) (defalias 'treepy--context-assoc #[385 "\300\301\302\303\"#\207" [seq-reduce #[514 "\300!\210\301\302\"\301\303\"\304#\207" [seqp seq--elt-safe 1 0 treepy--context-assoc-1] 10 "\n\n(fn CONTEXT KV)"] seq-partition 2] 7 (#$ . 3461)]) #@130 Return meta information for this LOC. If KEY is given, only return this key's value in meta information. (fn LOC &optional KEY) (defalias 'treepy--meta #[513 "A\203 \300\"\207\207" [map-elt] 6 (#$ . 3783)]) #@53 Bind OBJ with some META information. (fn OBJ META) (defalias 'treepy--with-meta #[514 "B\207" [] 4 (#$ . 4002)]) #@164 Return a joining of LEFT-CHILDREN and RIGHT-CHILDREN. Reverses LEFT-CHILDREN so that they are correctly ordered as in the tree. (fn LEFT-CHILDREN RIGHT-CHILDREN) (defalias 'treepy--join-children #[514 "\300\301!\"\207" [append reverse] 5 (#$ . 4125)]) #@98 Create a lexical context using LOC VARS. Execute BODY in this context. (fn LOC VARS &rest BODY) (defalias 'treepy--with-loc '(macro . #[642 "\300\301\302\"\"\303BB\207" [mapcar make-closure #[257 "\211\301\267\202\302\303\300DD\207\304\305\300DD\207\211\305\300\306\307\310\311!P!DED\207" [V0 #s(hash-table size 3 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (quote 6 node 6 context 12)) node treepy-node context treepy--context quote intern ":" symbol-name] 9 "\n\n(fn V)"] let*] 7 (#$ . 4386)])) (byte-code "\300\301\302\303#\300\207" [function-put treepy--with-loc lisp-indent-function defun] 4) #@415 Create a new zipper structure. BRANCHP is a function that, given a node, returns t if it can have children, even if it currently doesn't. CHILDREN is a function that, given a branch node, returns a seq of its children. MAKE-NODE is a function that, given an existing node and a seq of children, returns a new branch node with the supplied children. ROOT is the root node. (fn BRANCHP CHILDREN MAKE-NODE ROOT) (defalias 'treepy-zipper #[1028 "\300C\301B\302B\303BE\"\207" [treepy--with-meta :branchp :children :make-node] 10 (#$ . 5020)]) #@65 Return a zipper for nested lists, given a ROOT list. (fn ROOT) (defalias 'treepy-list-zip #[257 "\300\301\302\303$\207" [#[514 "\207" [] 3 "\n\n(fn _ CHILDREN)"] treepy-zipper listp identity] 7 (#$ . 5576)]) #@69 Return a zipper for nested vectors, given a ROOT vector. (fn ROOT) (defalias 'treepy-vector-zip #[257 "\300\301\302\303$\207" [#[514 "\300\301\"\207" [apply vector] 5 "\n\n(fn _ CHILDREN)"] #[257 "\300\301\"\207" [seq-into list] 4 "\n\n(fn CS)"] treepy-zipper vectorp] 8 (#$ . 5793)]) #@35 Return the node at LOC. (fn LOC) (defalias 'treepy-node #[257 "\211@@\207" [] 2 (#$ . 6091)]) #@52 Return t if the node at LOC is a branch. (fn LOC) (defalias 'treepy-branch-p #[257 "\300\301\"\302!!\207" [treepy--meta :branchp treepy-node] 4 (#$ . 6192)]) #@78 Return a children list of the node at LOC, which must be a branch. (fn LOC) (defalias 'treepy-children #[257 "\300!\203\301\302\"\303!!\207\304\305!\207" [treepy-branch-p treepy--meta :children treepy-node error "Called children on a leaf node"] 4 (#$ . 6359)]) #@175 Return a new branch node. Given an existing LOC, NODE and new CHILDREN, creates a new LOC with them. The LOC is only used to supply the constructor. (fn LOC NODE CHILDREN) (defalias 'treepy-make-node #[771 "\300\301\"\"\207" [treepy--meta :make-node] 6 (#$ . 6634)]) #@60 Return a list of nodes leading to the given LOC. (fn LOC) (defalias 'treepy-path #[257 "\300\301\302\"!\207" [reverse treepy--context :pnodes] 5 (#$ . 6912)]) #@59 Return a list of the left siblings of this LOC. (fn LOC) (defalias 'treepy-lefts #[257 "\300\301\302\"!\207" [reverse treepy--context :l] 5 (#$ . 7079)]) #@60 Return a list of the right siblings of this LOC. (fn LOC) (defalias 'treepy-rights #[257 "\300\301\"\207" [treepy--context :r] 4 (#$ . 7241)]) #@93 Return the loc of the leftmost child of the node at this LOC. nil if no children. (fn LOC) (defalias 'treepy-down #[257 "\300!\205O\301!\302!\303!\303\304\"\305!\210\306\307\"\310\311\"\205K\312\313C\304 \2038\n B\202;\nCB\314\nB\315B\257\316 !\"\266\207\262\207" [treepy-branch-p treepy-children treepy-node treepy--context :pnodes seqp seq-drop 1 seq--elt-safe 0 treepy--with-meta :l :ppath :r treepy--meta] 16 (#$ . 7392)]) #@84 Return the loc of the parent of the node at this LOC. nil if at the top. (fn LOC) (defalias 'treepy-up #[257 "\300!\301\302\"\301\303\"\301\304\"\301\305\"\301\306\"\205K@\307\203@\310 \311\fB\"#\205<\312\304\313#B\202DB\314\n!\"\262\207" [treepy-node treepy--context :pnodes :ppath :changed\? :l :r treepy--with-meta treepy-make-node treepy--join-children treepy--context-assoc t treepy--meta] 16 (#$ . 7853)]) #@102 Zip from LOC all the way up and return the root node. Reflect any alterations to the tree. (fn LOC) (defalias 'treepy-root #[257 "\300!\301=\203\f\302!\207\211\303!\211\262\203\211\262\202 \302!\207" [treepy--context :end treepy-node treepy-up] 4 (#$ . 8303)]) #@112 Return the loc of the right sibling of the node at this LOC. nil if there's no more right sibilings. (fn LOC) (defalias 'treepy-right #[257 "\300!\301!\301\302\"\301\303\"\211<\203\211\202\211C\304!\210\305\306\"\307\310\"\205E\205E\311\312\n\302 \fB\303%B\313\f!\"\207" [treepy-node treepy--context :l :r seqp seq-drop 1 seq--elt-safe 0 treepy--with-meta treepy--context-assoc treepy--meta] 18 (#$ . 8582)]) #@130 Return the loc of the rightmost sibling of the node at this LOC. If LOC is already the rightmost sibling, return self. (fn LOC) (defalias 'treepy-rightmost #[257 "\300!\301!\301\302\"\301\303\"\2033\211\2033\304\305!@\306\302\307\n\310 !B\"\303\311%B\312!\"\207\207" [treepy-node treepy--context :l :r treepy--with-meta last treepy--context-assoc treepy--join-children butlast nil treepy--meta] 15 (#$ . 9024)]) #@102 Return the loc of the left sibling of the node at this LOC. nil if no more left sibilings. (fn LOC) (defalias 'treepy-left #[257 "\300!\301!\301\302\"\301\303\"\205;\205;\304!\210\305\306\"\307\310\"\311\312 \302\303\fB%B\313 !\"\266\204\207" [treepy-node treepy--context :l :r seqp seq-drop 1 seq--elt-safe 0 treepy--with-meta treepy--context-assoc treepy--meta] 18 (#$ . 9460)]) #@128 Return the loc of the leftmost sibling of the node at this LOC. If LOC is already the leftmost sibling, return self. (fn LOC) (defalias 'treepy-leftmost #[257 "\300!\301!\301\302\"\301\303\"\2033\2033\304\305!@\306\302\307\303\310\311\n!\f\nB\"%B\312!\"\207\207" [treepy-node treepy--context :l :r treepy--with-meta last treepy--context-assoc [] treepy--join-children butlast treepy--meta] 16 (#$ . 9870)]) #@83 Return the leftmost descendant of the given LOC. (ie, down repeatedly). (fn LOC) (defalias 'treepy-leftmost-descendant #[257 "\300!\203\301!\262\202\207" [treepy-branch-p treepy-down] 3 (#$ . 10300)]) #@112 Insert as the left sibling of this LOC'S node the ITEM. Return same loc with sibilings updated. (fn LOC ITEM) (defalias 'treepy-insert-left #[514 "\300!\301!\301\302\"\204\303\304!\207\305\306\302B\307\310%B\311!\"\207" [treepy-node treepy--context :l error "Insert at top" treepy--with-meta treepy--context-assoc :changed\? t treepy--meta] 13 (#$ . 10516)]) #@113 Insert as the right sibling of this LOC's node the ITEM. Return same loc with sibilings updated. (fn LOC ITEM) (defalias 'treepy-insert-right #[514 "\300!\301!\301\302\"\204\303\304!\207\305\306\302B\307\310%B\311!\"\207" [treepy-node treepy--context :r error "Insert at top" treepy--with-meta treepy--context-assoc :changed\? t treepy--meta] 13 (#$ . 10897)]) #@82 Replace the node in this LOC with the given NODE, without moving. (fn LOC NODE) (defalias 'treepy-replace #[514 "\300!\301\302\303\304#B\305!\"\207" [treepy--context treepy--with-meta treepy--context-assoc :changed\? t treepy--meta] 9 (#$ . 11279)]) #@86 Replace the node at this LOC with the value of (F node ARGS). (fn LOC F &rest ARGS) (defalias 'treepy-edit #[642 "\300\301\302!#\"\207" [treepy-replace apply treepy-node] 9 (#$ . 11540)]) #@113 Insert as the leftmost child of this LOC's node the ITEM. Return same loc with children updated. (fn LOC ITEM) (defalias 'treepy-insert-child #[514 "\300\301\302!\303!B#\"\207" [treepy-replace treepy-make-node treepy-node treepy-children] 10 (#$ . 11741)]) #@114 Insert as the rightmost child of this LOC'S node the ITEM. Return same loc with children updated. (fn LOC ITEM) (defalias 'treepy-append-child #[514 "\300\301\302!\303\304!C\"#\"\207" [treepy-replace treepy-make-node treepy-node append treepy-children] 10 (#$ . 12013)]) #@101 Remove the node at LOC. Return the loc that would have preceded it in a depth-first walk. (fn LOC) (defalias 'treepy-remove #[257 "\300!\300\301\"\300\302\"\300\303\"\300\304\"\204\305\306!\207G\307V\203O\310@\311\303A\312\313%B\314!\"\315\316!\205?\317!\211\262\203M\320!\262\2026\207\310\321@#\205b\311\312\313#B\314!\"\207" [treepy--context :pnodes :ppath :l :r error "Remove at top" 0 treepy--with-meta treepy--context-assoc :changed\? t treepy--meta nil treepy-branch-p treepy-children treepy-rightmost treepy-make-node] 14 (#$ . 12300)]) #@194 Move to the next LOC in the hierarchy, depth-first in preorder. When reaching the end, returns a distinguished loc detectable via `treepy-end-p'. If already at the end, stays there. (fn LOC) (defalias 'treepy--preorder-next #[257 "\300!\301=\203 \207\211\302!\203\303!\206C\304!\206C\211\305\306!\2037\304\306!!\211\262\2047\306!\262\202\211\206A\307!\301BC\266\202\207" [treepy--context :end treepy-branch-p treepy-down treepy-right nil treepy-up treepy-node] 7 (#$ . 12889)]) #@195 Move to the next LOC in the hierarchy, depth-first in postorder. When reaching the end, returns a distinguished loc detectable via `treepy-end-p'. If already at the end, stays there. (fn LOC) (defalias 'treepy--postorder-next #[257 "\300!\301=\203 \207\302!\204\303!\301BC\207\304!\211\205 \305!\262\206(\302!\207" [treepy--context :end treepy-up treepy-node treepy-right treepy-leftmost-descendant] 4 (#$ . 13396)]) #@184 Move to the next LOC in the hierarchy, depth-first. Use ORDER if given. Possible values for ORDER are `:preorder' and `:postorder', defaults to the former. (fn LOC &optional ORDER) (defalias 'treepy-next #[513 "\211\206\300\211\301\267\202\302!\207\303!\207\304\305!\207" [:preorder #s(hash-table size 3 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (quote 11 :preorder 11 :postorder 15)) treepy--preorder-next treepy--postorder-next error "Unrecognized order"] 5 (#$ . 13834)]) #@113 Move to the previous LOC in the hierarchy, depth-first preorder. If already at the root, returns nil. (fn LOC) (defalias 'treepy--preorder-prev #[257 "\300!\301\203!\302!\205\303!\211\262\203\304!\262\202\207\305!\207" [treepy-left nil treepy-branch-p treepy-children treepy-rightmost treepy-up] 5 (#$ . 14346)]) #@114 Move to the previous LOC in the hierarchy, depth-first postorder. If already at the root, returns nil. (fn LOC) (defalias 'treepy--postorder-prev #[257 "\300!\203\f\301\302!!\207\303!\204\304!\262\202\f\303!\207" [treepy-branch-p treepy-rightmost treepy-down treepy-left treepy-up] 4 (#$ . 14683)]) #@188 Move to the previous LOC in the hierarchy, depth-first. Use ORDER if given. Possible values for ORDER are `:preorder' and `:postorder', defaults to the former. (fn LOC &optional ORDER) (defalias 'treepy-prev #[513 "\211\206\300\211\301\267\202\302!\207\303!\207\304\305!\207" [:preorder #s(hash-table size 3 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (quote 11 :preorder 11 :postorder 15)) treepy--preorder-prev treepy--postorder-prev error "Unrecognized order"] 5 (#$ . 15000)]) #@69 Return t if LOC represents the end of a depth-first walk. (fn LOC) (defalias 'treepy-end-p #[257 "\300!\301=\207" [treepy--context :end] 3 (#$ . 15515)]) (provide 'treepy)