on 8564483 help sign in
147 lines 1.9 kB history raw
1---
2navhome: /docs
3---
6# 1b: tree addressing
7### `++cap`
9Tree head
11Tests whether an `a` is in the head or tail of a noun. Produces the
12cube `%2` if it is within the head, or the cube `%3` if it is
13within the tail.
15Accepts
16-------
18`a` is an atom.
20Produces
21--------
23A cube.
25Source
26------
28 ++ cap :: tree head
29 ~/ %cap
30 |= a=@
31 ^- ?(%2 %3)
32 ?- a
33 %2 %2
34 %3 %3
35 ?(%0 %1) !!
36 * $(a (div a 2))
37 ==
38 ::
40Examples
41--------
43 > (cap 4)
44 %2
45 > (cap 6)
46 %3
47 > (cap (add 10 9))
48 %2
52***
53### `++mas`
55Axis within head/tail?
57Computes the axis of `a` within either the head or tail of a noun (depends whether `a` lies within the the head or tail).
59Accepts
60-------
62`a` is an [atom]().
64Produces
65--------
67An atom.
69Source
70------
72 ++ mas :: tree body
73 ~/ %mas
74 |= a=@
75 ^- @
76 ?- a
77 1 !!
78 2 1
79 3 1
80 * (add (mod a 2) (mul $(a (div a 2)) 2))
81 ==
82 ::
84Examples
85--------
87 > (mas 3)
88 1
89 > (mas 4)
90 2
91 > (mas 5)
92 3
93 > (mas 6)
94 2
95 > (mas 0)
96 ! exit
97 > (mas 1)
98 ! exit
102***
103### `++peg`
105Axis within axis
107Computes the axis of `b` within axis `a`.
109Accepts
110-------
112`a` is an atom.
114`b` is an atom.
116Produces
117--------
119An atom.
121Source
122------
124 ++ peg :: tree connect
125 ~/ %peg
126 |= {a/@ b/@}
127 ^- @
128 ?- b
129 $1 a
130 $2 (mul a 2)
131 $3 +((mul a 2))
132 * (add (mod b 2) (mul $(b (div b 2)) 2))
133 ==
135Examples
136--------
138 > (peg 4 1)
139 4
140 > (peg 4 2)
141 8
142 > (peg 8 45)
143 269
147***