# 1b: tree addressing ### `++cap` Tree head Tests whether an `a` is in the head or tail of a noun. Produces the cube `%2` if it is within the head, or the cube `%3` if it is within the tail. Accepts ------- `a` is an atom. Produces -------- A cube. Source ------ ++ cap :: tree head ~/ %cap |= a=@ ^- ?(%2 %3) ?- a %2 %2 %3 %3 ?(%0 %1) !! * $(a (div a 2)) == :: Examples -------- > (cap 4) %2 > (cap 6) %3 > (cap (add 10 9)) %2 *** ### `++mas` Axis within head/tail? Computes the axis of `a` within either the head or tail of a noun (depends whether `a` lies within the the head or tail). Accepts ------- `a` is an [atom](). Produces -------- An atom. Source ------ ++ mas :: tree body ~/ %mas |= a=@ ^- @ ?- a 1 !! 2 1 3 1 * (add (mod a 2) (mul $(a (div a 2)) 2)) == :: Examples -------- > (mas 3) 1 > (mas 4) 2 > (mas 5) 3 > (mas 6) 2 > (mas 0) ! exit > (mas 1) ! exit *** ### `++peg` Axis within axis Computes the axis of `b` within axis `a`. Accepts ------- `a` is an atom. `b` is an atom. Produces -------- An atom. Source ------ ++ peg :: tree connect ~/ %peg |= {a/@ b/@} ^- @ ?- b $1 a $2 (mul a 2) $3 +((mul a 2)) * (add (mod b 2) (mul $(b (div b 2)) 2)) == Examples -------- > (peg 4 1) 4 > (peg 4 2) 8 > (peg 8 45) 269 ***