!!
puzzles-4
=< (qort `(list @)`~[3 1 4 1 5 9 2 6]) |% ++ qort |= xs=(list @) ^- (list @) ?~ xs ~ =/ less %+ skim t.xs |= x=@ (lth x i.xs) =/ more %+ skim t.xs |= x=@ (gte x i.xs) %+ weld (qort less) [i.xs (qort more)] --

divide, conquer

glossary

=< evaluates its head against its tail as subject.

=<(a b) is =>(b a), and =<(a [a=5]) is 5.

irregular forms:

arm:core is =<(arm core)

%: calls a gate with several arguments, gathering them into one sample.

%:(add 2 3) is 5.

irregular forms:

(gate a b c) is %:(gate a b c)

^- casts a value to a named type: it checks the value fits and relabels it.

^-(@ 42) is 42.

irregular forms:

a leading backtick cast - the type in backticks, then the value - is ^-

list is the type of a null-terminated sequence.

(list @) is a list of atoms; the empty list is ~.

:~ makes a null-terminated list.

:~(1 2 3) is ~[1 2 3].

irregular forms:

~[a b c] is :~(a b c)

|% makes a core: a battery of named arms, each written ++ name.

reach an arm back out with =< or arm:core.

=<  a
|%
++  a  5
--

is 5.

|= makes a gate: a function with one named sample, then a body.

the body runs with the sample bound.

call the gate to run it.

(|=(a=@ (add a 1)) 4) is 5.

$= wraps a mold with a face, naming the value it produces.

$=(x @) is the mold x=@.

?~ branches on whether a value is ~ (null): first branch if it is, second if not.

=/(a=(unit @) ~ ?~(a 0 u.a)) is 0.

=/ pins a named value (a face) into the subject for the lines below it.

name=value optionally declares the type.

=/(a 3 (add a a)) is 6.

%+ calls a gate that takes two arguments.

%+(add 2 3) is 5.

irregular forms:

(gate a b) is %+(gate a b)

skim keeps the list elements a gate says yes to.

(skim `(list @)`~[1 2 3 4] |=(n=@ (gth n 2))) is ~[3 4].

lth asks whether the first atom is strictly less than the second.

(lth 5 3) is %.n.

gte is greater-than-or-equal.

(gte 5 5) is %.y.

weld joins two lists end to end.

(weld `(list @)`~[1 2] `(list @)`~[3 4]) is ~[1 2 3 4].

:* makes a tuple of many elements, nesting to the right.

:*(1 2 3) is [1 2 3].

irregular forms:

[a b c d] is :*(a b c d)