@@ -1,8 +1,8 @@
11---
22navhome: /docs/
3−sort: 17
4−title: Examples
53next: true
4+sort: 21
5+title: Examples
66---
77
88# Examples
@@ -18,29 +18,30 @@ side of simple manual construction over high-octane FP.)
1818
1919A function that produces the list of primes less than or equal to
2020its argument, an atom:
21+
2122```
22−:gate thru/atom :: 1
23−:cast (list atom) :: 2
24−:var field/(set atom) (silt (gulf 2 thru)) :: 3
25−:rap abet:main :: 4
26−:core :: 5
23+|= thru/@ :: 1
24+^- (list @) :: 2
25+=/ field/(set @) (silt (gulf 2 thru)) :: 3
26+=< abet:main :: 4
27+|% :: 5
2728++ abet :: 6
2829 (sort (~(tap in field) ~) lth) :: 7
2930:: :: 8
3031++ main :: 9
31− :var factor/atom 2 :: 10
32− :loop :like ..main :: 11
33− :if (gth (mul factor factor) thru) :: 12
32+ =/ factor/@ 2 :: 10
33+ |- ^+ ..main :: 11
34+ ?: (gth (mul factor factor) thru) :: 12
3435 ..main :: 13
35− :moar(factor +(factor), ..main (reap factor)) :: 14
36+ $(factor +(factor), ..main (reap factor)) :: 14
3637:: :: 15
3738++ reap :: 16
38− :gate factor/atom :: 17
39− :var count/atom (mul 2 factor) :: 18
40− :loop :like ..reap :: 19
41− :if (gth count thru) :: 20
39+ |= factor/@ :: 17
40+ =/ count/@ (mul 2 factor) :: 18
41+ |- ^+ ..reap :: 19
42+ ?: (gth count thru) :: 20
4243 ..reap :: 21
43− :moar :: 22
44+ %= $ :: 22
4445 count (add count factor) :: 23
4546 field (~(del in field) count) :: 24
4647 == :: 25
@@ -50,9 +51,9 @@ its argument, an atom:
5051## `sieve`: explanation
5152
5253```
53−:gate thru/atom :: 1
54−:cast (list atom) :: 2
55−:var field/(set atom) (silt (gulf 2 thru)) :: 3
54+|= thru/@ :: 1
55+^- (list @) :: 2
56+=/ field/(set @) (silt (gulf 2 thru)) :: 3
5657```
5758
5859Line `1`: we are building a gate (function) whose sample
@@ -67,13 +68,13 @@ list of atoms.
6768
6869Line `4`: below, we introduce a core which does our work. With
6970reverse flow, we compute `main` on this core, then `abet` on the
70−product of `main`. (`abet:main` means `:rap(abet main)`.)
71+product of `main`. (`abet:main` means `=<(abet main)`.)
7172
7273The core is a state machine; `main` produces the core itself,
7374with the computation completed. `abet` then extracts the result.
7475
7576```
76−:core :: 5
77+|% :: 5
7778++ abet :: 6
7879 (sort (~(tap in field) ~) lth) :: 7
7980```
@@ -90,8 +91,8 @@ list in ascending order with `lth` (less-than).
9091
9192```
9293++ main :: 9
93− :var factor/atom 2 :: 10
94− :loop :like ..main :: 11
94+ =/ factor/@ 2 :: 10
95+ |- ^+ ..main :: 11
9596```
9697
9798Line `9`: the `main` arm, which performs the main calculation.
@@ -103,9 +104,9 @@ Line `11`: we start a loop. The product of the loop is cast to
103104`..main`, which is the core we're in (`+1.main`).
104105
105106```
106− :if (gth (mul factor factor) thru) :: 12
107+ ?: (gth (mul factor factor) thru) :: 12
107108 ..main :: 13
108− :moar(factor +(factor), ..main (reap factor)) :: 14
109+ $(factor +(factor), ..main (reap factor)) :: 14
109110```
110111
111112Lines `12` and `13`: we terminate the loop, returning `..main`,
@@ -116,8 +117,8 @@ replacing the core with a version sieved by `reap`.
116117
117118```
118119++ reap :: 16
119− :gate factor/atom :: 17
120− :var count/atom (mul 2 factor) :: 18
120+ |= factor/@ :: 17
121+ =/ count/@ (mul 2 factor) :: 18
121122```
122123
123124Lines `16` and `17`: the `reap` arm, which produces a gate that
@@ -128,10 +129,10 @@ Line `18`: we declare a variable `count`, an atom, with the
128129initial value `(mul 2 factor)`.
129130
130131```
131− :loop :like ..reap :: 19
132− :if (gth count thru) :: 20
132+ |- ^+ ..reap :: 19
133+ ?: (gth count thru) :: 20
133134 ..reap :: 21
134− :moar :: 22
135+ %= $ :: 22
135136 count (add count factor) :: 23
136137 field (~(del in field) count) :: 24
137138 == :: 25
@@ -147,9 +148,7 @@ multiple of `factor`, and deleting it from `field`.
147148
148149## `sieve`: code in kernel style
149150
150−Finally, the same code transliterated into runes (and in a more
151−concise "kernel" style).
152−
151+Finally, the same code in a more concise "kernel" style.
153152```
154153|= top/@
155154^- (list @)
@@ -165,7 +164,7 @@ concise "kernel" style).
165164 $(fac +(fac), ..main (reap fac))
166165::
167166++ reap
168− |= fac/atom
167+ |= fac/@
169168 =+ cot=(mul 2 fac)
170169 |- ^+ ..reap
171170 ?: (gth cot top)
@@ -181,65 +180,65 @@ state, producing a list of game actions. Events are tic-tac-toe
181180moves (`move)`; actions are tic-tac-toe results (`fact`).
182181
183182```
184−:rap :gate feed/(list move) :: 1
185− :new game/game :: 2
186− :loop :cast (list fact) :: 3
187− :ifno feed ~ :: 4
188− :sip this/(unit fact) :: 5
189− game :: 6
190− (~(do go game) i.feed) :: 7
191− :var rest/(list fact) :moar(feed t.feed) :: 8
192− :ifno(this rest [u.this rest]) :: 9
183+=< |= feed/(list move) :: 1
184+ =| game/game :: 2
185+ |- ^- (list fact) :: 3
186+ ?~ feed ~ :: 4
187+ =^ this/(unit fact) :: 5
188+ game :: 6
189+ (~(do go game) i.feed) :: 7
190+ =/ rest/(list fact) $(feed t.feed) :: 8
191+ ?~(this rest [u.this rest]) :: 9
193192:: :: 10
194−:per :core :: 11
195− ++ side atom :: 12
196− ++ spot {x/atom y/atom} :: 13
197− ++ fact :book {$tie $~} :: 14
198− {$win p/cord} :: 15
199− == :: 16
200− ++ move :book {$x p/spot} :: 17
201− {$o p/spot} :: 18
202− {$z $~} :: 19
203− == :: 20
204− ++ game :bank w/? :: 21
205− a/side :: 22
206− z/side :: 23
207− == :: 24
208− -- :: 25
209−:core :: 26
193+=> |% :: 11
194+ ++ side @ :: 12
195+ ++ spot {x/@ y/@} :: 13
196+ ++ fact $% {$tie $~} :: 14
197+ {$win p/cord} :: 15
198+ == :: 16
199+ ++ move $% {$x p/spot} :: 17
200+ {$o p/spot} :: 18
201+ {$z $~} :: 19
202+ == :: 20
203+ ++ game $: w/? :: 21
204+ a/side :: 22
205+ z/side :: 23
206+ == :: 24
207+ -- :: 25
208+|% :: 26
210209++ bo :: 27
211− :door half/side :: 28
212− ++ bit :gate(a/atom =(1 (cut 0 [a 1] half))) :: 29
213− ++ off :gate(a/spot (add x.a (mul 3 y.a))) :: 30
214− ++ get :gate(a/spot (bit (off a))) :: 31
215− ++ set :gate(a/spot (con half (bex (off a)))) :: 32
216− ++ win :calt lien :: 33
210+ |_ half/side :: 28
211+ ++ bit |=(a/@ =(1 (cut 0 [a 1] half))) :: 29
212+ ++ off |=(a/spot (add x.a (mul 3 y.a))) :: 30
213+ ++ get |=(a/spot (bit (off a))) :: 31
214+ ++ set |=(a/spot (con half (bex (off a)))) :: 32
215+ ++ win %+ lien :: 33
217216 (rip 4 0wl04h0.4A0Aw.4A00s.0e070) :: 34
218− :gate(a/atom =(a (dis a half))) :: 35
217+ |=(a/@ =(a (dis a half))) :: 35
219218 -- :: 36
220219++ go :: 37
221− :door game/game :: 38
220+ |_ game/game :: 38
222221 ++ do :: 39
223− :gate act/move :: 40
224− :cast {(unit fact) ^game} :: 41
225− :case act :: 42
226− {$x *} :sure(w.game ~(mo on p.act)) :: 43
227− {$o *} :deny(w.game ~(mo on p.act)) :: 44
222+ |= act/move :: 40
223+ ^- {(unit fact) ^game} :: 41
224+ ?- act :: 42
225+ {$x *} ?>(w.game ~(mo on p.act)) :: 43
226+ {$o *} ?<(w.game ~(mo on p.act)) :: 44
228227 {$z *} [~ nu] :: 45
229228 == :: 46
230229 :: :: 47
231− ++ nu :like(game [& 0 0]) :: 48
230+ ++ nu ^+(game [& 0 0]) :: 48
232231 ++ on :: 49
233− :door here/spot :: 50
234− ++ is :or (~(get bo a.game) here) :: 51
235− (~(get bo z.game) here) :: 52
236− == :: 53
237− ++ mo :cast {(unit fact) ^game} :: 54
238− :deny is :: 55
239− :var next/side (~(set bo a.game) here) :: 56
240− :if ~(win bo next) :: 57
241− [[~ %win ?:(w.game %x %o)] nu] :: 58
242− [~ game(w !w.game, a z.game, z next)] :: 59
232+ |_ here/spot :: 50
233+ ++ is ?| (~(get bo a.game) here) :: 51
234+ (~(get bo z.game) here) :: 52
235+ == :: 53
236+ ++ mo ^- {(unit fact) ^game} :: 54
237+ ?< is :: 55
238+ =/ next/side (~(set bo a.game) here) :: 56
239+ ?: ~(win bo next) :: 57
240+ [[~ %win ?:(w.game %x %o)] nu] :: 58
241+ [~ game(w !w.game, a z.game, z next)] :: 59
243242 -- :: 60
244243 -- :: 62
245244-- :: 63
@@ -248,10 +247,10 @@ moves (`move)`; actions are tic-tac-toe results (`fact`).
248247### `toe`: explanation
249248
250249```
251−:rap :gate feed/(list move) :: 1
252− :new game/game :: 2
253− :loop :cast (list fact) :: 3
254− :ifno feed ~ :: 4
250+=< |= feed/(list move) :: 1
251+ =| game/game :: 2
252+ |- ^- (list fact) :: 3
253+ ?~ feed ~ :: 4
255254```
256255
257256Line `1` wraps a conclusion around a stack of cores. The cores
@@ -268,7 +267,7 @@ Line `3` enters a loop producing a list of game events, `fact`.
268267Line `4` produces nil, `~`, if `feed` is empty.
269268
270269```
271− :sip this/(unit fact) :: 5
270+ =^ this/(unit fact) :: 5
272271 game :: 6
273272 (~(do go game) i.feed) :: 7
274273```
@@ -277,12 +276,12 @@ Lines `5` through `7` apply the move. We open a `go` core on the
277276current game state, produce a `do` gate, and call that gate on
278277the move. The product of the `do` gate is a pair; the head is
279278`(unit fact)`, either `~` or `[~ fact]`; the tail is a new
280−`game`. The `:sip` twig declares the head as a new variable,
279+`game`. The `=^` hoon declares the head as a new variable,
281280`this`; it modifies the subject by setting `game` to the tail.
282281
283282```
284− :var rest/(list fact) :moar(feed t.feed) :: 8
285− :ifno(this rest [u.this rest]) :: 9
283+ =/ rest/(list fact) $(feed t.feed) :: 8
284+ ?~(this rest [u.this rest]) :: 9
286285```
287286
288287Line `8` declares a new variable, `rest`, which is all the facts
@@ -292,9 +291,9 @@ generated by the moves in `t.feed`, the tail of the move list.
292291prepends the new fact to `rest`.
293292
294293```
295−:per :core :: 11
296− ++ side atom :: 12
297− ++ spot {x/atom y/atom} :: 13
294+=> |% :: 11
295+ ++ side @ :: 12
296+ ++ spot {x/@ y/@} :: 13
298297```
299298
300299Line `11` wraps a library core around a data structure core, a
@@ -308,9 +307,9 @@ A side is a half of the board, as a marked/unmarked bitfield.
308307Line `13` defines the `spot` mold, a 2D coordinate.
309308
310309```
311− ++ fact :book {$tie $~} :: 14
312− {$win p/cord} :: 15
313− == :: 16
310+ ++ fact $% {$tie $~} :: 14
311+ {$win p/cord} :: 15
312+ == :: 16
314313```
315314
316315Lines `14` to `16` define the `fact` mold, a game event (i.e.,
@@ -319,21 +318,21 @@ output action), as a book (tagged union). There are two forms of
319318(reporting that `'X'` or `'O'` won a game.
320319
321320```
322− ++ move :book {$x p/spot} :: 17
323− {$o p/spot} :: 18
324− {$z $~} :: 19
325− == :: 20
321+ ++ move $% {$x p/spot} :: 17
322+ {$o p/spot} :: 18
323+ {$z $~} :: 19
324+ == :: 20
326325```
327326
328327Lines `17` to `20` define the `move` mold, a game move. This is
329328either `[%x spot]`, `[%o spot]`, or `[%z ~]` to reset the board.
330329
331330```
332− ++ game :bank w/? :: 21
333− a/side :: 22
334− z/side :: 23
335− == :: 24
336− -- :: 25
331+ ++ game $: w/? :: 21
332+ a/side :: 22
333+ z/side :: 23
334+ == :: 24
335+ -- :: 25
337336```
338337
339338Lines `21` to `23` define the `game` mold, the game state. This
@@ -342,13 +341,13 @@ side; and `w`, which is `&` (yes) if `a` is X and `b` is O; `|`
342341otherwise. (Obviously, we swap `a` and `z` on every move.)
343342
344343```
345−:core :: 26
344+|% :: 26
346345++ bo :: 27
347− :door half/side :: 28
348− ++ bit :gate(a/atom =(1 (cut 0 [a 1] half))) :: 29
349− ++ off :gate(a/spot (add x.a (mul 3 y.a))) :: 30
350− ++ get :gate(a/spot (bit (off a))) :: 31
351− ++ set :gate(a/spot (con half (bex (off a)))) :: 32
346+ |_ half/side :: 28
347+ ++ bit |=(a/@ =(1 (cut 0 [a 1] half))) :: 29
348+ ++ off |=(a/spot (add x.a (mul 3 y.a))) :: 30
349+ ++ get |=(a/spot (bit (off a))) :: 31
350+ ++ set |=(a/spot (con half (bex (off a)))) :: 32
352351```
353352
354353Line `26` introduces the library core, which contains the doors
@@ -369,9 +368,9 @@ bit at a `spot` set. It works by ORing (`con`) `half` with the
369368binary exponent (`bex`) of the offset (`off`) of the spot.
370369
371370```
372− ++ win :calt lien :: 33
371+ ++ win %+ lien :: 33
373372 (rip 4 0wl04h0.4A0Aw.4A00s.0e070) :: 34
374− :gate(a/atom =(a (dis a half))) :: 35
373+ |=(a/@ =(a (dis a half))) :: 35
375374 -- :: 36
376375```
377376
@@ -383,10 +382,10 @@ of which must equal itself when ANDed (`dis`) with `half`.
383382
384383```
385384++ go :: 37
386− :door game/game :: 38
385+ |_ game/game :: 38
387386 ++ do :: 39
388− :gate act/move :: 40
389− :cast {(unit fact) ^game} :: 41
387+ |= act/move :: 40
388+ ^- {(unit fact) ^game} :: 41
390389```
391390
392391Lines `37` to `38` begin the `go` core, a door around a `game`.
@@ -398,9 +397,9 @@ move. The product is cast to a pair of `(unit fact)` and a new
398397game state, written `^game` to skip to the second binding.
399398
400399```
401− :case act :: 42
402− {$x *} :sure(w.game ~(mo on p.act)) :: 43
403− {$o *} :deny(w.game ~(mo on p.act)) :: 44
400+ ?- act :: 42
401+ {$x *} ?>(w.game ~(mo on p.act)) :: 43
402+ {$o *} ?<(w.game ~(mo on p.act)) :: 44
404403 {$z *} [~ nu] :: 45
405404 == :: 46
406405 :: :: 47
@@ -412,12 +411,12 @@ the `mo` door to apply the move. If it's a `%z` move, we clear
412411the board.
413412
414413```
415− ++ nu :like(game [& 0 0]) :: 48
414+ ++ nu ^+(game [& 0 0]) :: 48
416415 ++ on :: 49
417− :door here/spot :: 50
418− ++ is :or (~(get bo a.game) here) :: 51
419− (~(get bo z.game) here) :: 52
420− == :: 53
416+ |_ here/spot :: 50
417+ ++ is ?| (~(get bo a.game) here) :: 51
418+ (~(get bo z.game) here) :: 52
419+ == :: 53
421420```
422421
423422Line `48` is the `nu` arm, which produces a blank game state.
@@ -427,16 +426,16 @@ Lines `49` to `50` begin the `on` door, a door around `here`, a
427426game state, we have multiple computed attributes (`is` and `mo`)
428427against the combination of game state and coordinate.
429428
430−Lines `51` to `53` define the `is` arm, which is `&` (yes) iff
429+Lines `51` to `53` define the `is` arm, which is `&` (yes) if
431430either `a` or `z` has played `here`.
432431
433432```
434− ++ mo :cast {(unit fact) ^game} :: 54
435− :deny is :: 55
436− :var next/side (~(set bo a.game) here) :: 56
437− :if ~(win bo next) :: 57
438− [[~ %win ?:(w.game %x %o)] nu] :: 58
439− [~ game(w !w.game, a z.game, z next)] :: 59
433+ ++ mo ^- {(unit fact) ^game} :: 54
434+ ?< is :: 55
435+ =/ next/side (~(set bo a.game) here) :: 56
436+ ?: ~(win bo next) :: 57
437+ [[~ %win ?:(w.game %x %o)] nu] :: 58
438+ [~ game(w !w.game, a z.game, z next)] :: 59
440439 -- :: 60
441440 -- :: 62
442441-- :: 63
@@ -487,13 +486,13 @@ side `z`, and replaces `z` with `next`.
487486|%
488487++ bo
489488 |_ haf/side
490− ++ bit |=(a/atom =(1 (cut 0 [a 1] haf)))
489+ ++ bit |=(a/@ =(1 (cut 0 [a 1] haf)))
491490 ++ get |=(a/spot (bit (off a)))
492491 ++ off |=(a/spot (add x.a (mul 3 y.a)))
493492 ++ set |=(a/spot (con haf (bex (off a))))
494493 ++ win %+ lien
495494 (rip 4 0wl04h0.4A0Aw.4A00s.0e070)
496− |=(a/atom =(a (dis a haf)))
495+ |=(a/@ =(a (dis a haf)))
497496 --
498497++ go
499498 |_ mag/game
@@ -510,9 +509,9 @@ side `z`, and replaces `z` with `next`.
510509 ++ on
511510 =| her/spot
512511 |%
513− ++ is ?| (~(get bo a.mag) her)
514− (~(get bo z.mag) her)
515− ==
512+ ++ is ?| (~(get bo a.mag) her)
513+ (~(get bo z.mag) her)
514+ ==
516515 ++ mo ^- {(unit fact) game}
517516 ?< is
518517 =+ next=(~(set bo a.mag) her)
@@ -563,28 +562,28 @@ side `z`, and replaces `z` with `next`.
563562::::
564563::::
565564
566−++ tree |* a/gate :: binary tree
565+++ tree |* a/gate :: binary tree
567566 $@($~ {n/a l/(tree a) r/(tree a)}) ::
568567++ trap |*(a/_* _|?(*a)) :: makes perfect sense
569−++ trel |* {a/gate b/gate c/gate} :: just a triple
568+++ trel |* {a/gate b/gate c/gate} :: just a triple
570569 {p/a q/b r/c} ::
571570++ each |* {a/gate b/gate} :: either a or b
572571 $%({$& p/a} {$| p/b}) :: a default
573572
574−++ qual |* {a/gate b/gate c/gate d/gate} :: just a quadruple
573+++ qual |* {a/gate b/gate c/gate d/gate} :: just a quadruple
575574 {p/a q/b r/c s/d} ::
576−++ pair |*({a/gate b/gate} {p/a q/b}) :: just a pair
577−++ quid |*({a/gate b/*} {a _b}) :: for =^
578−++ quip |*({a/gate b/*} {(list a) _b}) :: for =^
579−++ unit |* a/gate :: maybe
575+++ pair |*({a/gate b/gate} {p/a q/b}) :: just a pair
576+++ quid |*({a/gate b/*} {a _b}) :: for =^
577+++ quip |*({a/gate b/*} {(list a) _b}) :: for =^
578+++ unit |* a/gate :: maybe
580579 $@($~ {$~ u/a}) ::
581−++ list |* a/gate :: null-term list
580+++ list |* a/gate :: null-term list
582581 $@($~ {i/a t/(list a)}) ::
583−++ lone |*(a/gate p/a) :: just one thing
582+++ lone |*(a/gate p/a) :: just one thing
584583
585584::::
586585::::
587−++ map |* {a/gate b/gate} :: associative tree
586+++ map |* {a/gate b/gate} :: associative tree
588587 $@($~ {n/{p/a q/b} l/(map a b) r/(map a b)}) ::
589588++ qeu |* a/gate :: queue
590589 $@($~ {n/a l/(qeu a) r/(qeu a)}) ::