3 title/'1b: Tree Addressing'
10Check out the Nock [explanation](docs/nock/explanation/) for more
11information on the tree-addressing system.
13### `++cap`(#anchors-in-markdown))
17Tests whether the tree address `a` is in the head or the tail of a noun.
18Produces the constant atom `%2` if it is within the head (subtree `+2`), or
19the constant atom `%3` if it is within the tail (subtree `+3`).
57 > (cap 1) ::address '1' is in neither the head nor the tail
74Address within head/tail
76Computes the tree address of atom `a` within either the head (`+2`) or tail
98 * (add (mod a 2) (mul $(a (div a 2)) 2))
113 > (cap 5) ::`(cap a)` computes whether address `a` is in the head or the tail
131 ! exit ::address `0` is in neither the head nor the tail
134 ! exit ::address `1` is in neither the head nor the tail
143 2 3 <--here are the head (`+2`) and the tail (`+3`)
150Running `(mas 7)` in the Dojo will return `3`, because address `+3` is what
151`+7` now occupies. The tree below helps illustrate the relationship. With
152parentheses are `a` values (if `a` is in subtree `+3`), and without parentheses
153are the values returned with `(mas a)`.
156 1(3) ::new/(old) addresses
168Notice how the old values in the head (subtree `+2`) were not illustrated in
169this case, because `+7` is within the tail (subtree `+3`).
174Address within address
176Computes the absolute address of `b`, a relative address within the subtree
201 * (add (mod b 2) (mul $(b (div b 2)) 2))
226 > (cap (peg 4 2)) ::`(cap a)` computes whether address `a` is in the head or the tail
233In other words, the subtree at address `a` is treated as a tree in its own
234right (starting with root `+1`, head `+2`, and tail `+3`). Relative address
235`b` is found with respect to `a`, and then its absolute address, within the
236greater tree, is returned.
238Running `(peg 3 4)` in the Dojo, for example, will return `12`. Looking at
239a tree diagram makes it easy to see why.
246 2 3 <- here is the subtree `+3`. The subtree address is `a` in `(peg a b)`
251 8 9 10 11 12 13 14 15
252 /\ /\ /\ /\ /\ /\ /\ /\
256When we consider subtree at address `+3` by itself, it has relative addresses
257that are structured in the same way as its parent tree's absolute addresses.
258The absolute addresses are given in parentheses in the diagram below.
259Notice how relative address `+4` is at the same position as absolute address
263 1(3) ::new/(old) addresses
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list