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