@@ -4,28 +4,132 @@ navhome: /docs/
44
55
66# 2b: list logic
7−Reverse
7+### `++fand`
8+
9+All indices in `list`
10+
11+Produces the indices of all occurrences of `list` `nedl` in
12+`list` `hstk` as a `list` of atoms.
13+
14+#### Accepts
15+
16+`nedl` is a list.
17+
18+`hstk` is a list.
19+
20+#### Produces
21+
22+A `list`.
23+
24+#### Source
25+
26+ ++ fand :: all indices
27+ ~/ %fand
28+ |= [nedl=(list) hstk=(list)]
29+ =| i=@ud
30+ =| fnd=(list @ud)
31+ |- ^+ fnd
32+ =+ [n=nedl h=hstk]
33+ |-
34+ ?: |(?=($~ n) ?=($~ h))
35+ (flop fnd)
36+ ?: =(i.n i.h)
37+ ?~ t.n
38+ ^$(i +(i), hstk +.hstk, fnd [i fnd])
39+ $(n t.n, h t.h)
40+ ^$(i +(i), hstk +.hstk)
41+
42+
43+#### Examples
44+
45+ > (fand [3]~ ~[1 2 3])
46+ ~[2]
47+
48+ > (fand [4]~ ~[1 2 3])
49+ ~
50+
51+ > (fand ['a']~ "cbabab")
52+ ~[2 4]
53+
54+ > (fand "ba" "cbabab")
55+ ~[1 3]
56+
57+
58+
59+***
60+### `++find`
61+
62+First index in `list`
63+
64+Produces the index of the first occurrence of `list` `nedl` in
65+`list` `hstk` as the `unit` of an atom.
66+
67+#### Accepts
68+
69+`nedl` is a list.
70+
71+`hstk` is a list.
72+
73+#### Produces
74+
75+The `unit` of an atom.
76+
77+#### Source
78+
79+ ++ find :: first index
80+ ~/ %find
81+ |= [nedl=(list) hstk=(list)]
82+ =| i=@ud
83+ |- ^- (unit @ud)
84+ =+ [n=nedl h=hstk]
85+ |-
86+ ?: |(?=($~ n) ?=($~ h))
87+ ~
88+ ?: =(i.n i.h)
89+ ?~ t.n
90+ `i
91+ $(n t.n, h t.h)
92+ ^$(i +(i), hstk +.hstk)
93+
94+
95+#### Examples
96+
97+ > (find [3]~ ~[1 2 3])
98+ [~ u=2]
99+
100+ > (find [4]~ ~[1 2 3])
101+ ~
102+
103+ > (find ['c']~ "cbabab")
104+ [~ u=0]
105+
106+ > (find "ab" "cbabab")
107+ [~ u=1]
8108
109+ > (find "bab" "cbabab")
110+ [~ u=2]
111+
112+
113+***
9114### `++flop`
10115
11−Produces the list `a` in reverse order.
116+Reverse
12117
13−Accepts
14−-------
118+Produces the `list` `a` in reverse order.
15119
16−`a` is a list.
120+#### Accepts
17121
18−Produces
19−--------
122+`a` is a `list`.
20123
21−A list.
124+#### Produces
125+
126+A `list`.
22127
23−Source
24−------
128+#### Source
25129
26130 ++ flop :: reverse
27131 ~/ %flop
28− |* a/(list)
132+ |* a=(list)
29133 => .(a (homo a))
30134 ^+ a
31135 =+ b=`_a`~
@@ -35,46 +139,75 @@ Source
35139
36140
37141
38−Examples
39−--------
142+#### Examples
40143
41− > =a (limo [1 2 3 ~])
144+ > =a [1 2 3 ~]
42145 > (flop a)
43146 ~[3 2 1]
44147
148+ > (flop (flop a))
149+ ~[1 2 3]
150+
151+***
152+### `++gulf`
153+
154+List from range
155+
156+Produces a `list` composed of each consecutive integer starting from `a` and
157+ending with `b`. `a` and `b` are themselves included.
158+
159+#### Accepts
160+
161+`a` is an atom.
45162
163+`b` is an atom.
164+
165+#### Produces
166+
167+a `list`.
168+
169+#### Source
170+
171+ ++ gulf :: range inclusive
172+ |= [a=@ b=@]
173+ ^- (list @)
174+ ?:(=(a +(b)) ~ [a $(a +(a))])
175+
176+#### Examples
177+
178+ > (gulf 1 6)
179+ ~[1 2 3 4 5 6]
180+
181+ > `(list @t)`(gulf 99 106)
182+ <|c d e f g h i j|>
46183
47184***
48185### `++homo`
49186
50187Homogenize
51188
52−Produces a `++list` whose type is a fork of all the contained types in the
189+Produces a `list` whose type is a fork of all the contained types in the
53190list `a`. Used when you want to make all the types of the elements of a list the same.
54191
55−Accepts
56−-------
192+#### Accepts
57193
58−`a` is a list.
194+`a` is a `list`.
59195
60−Produces
61−--------
196+#### Produces
62197
63−a list.
198+a `list`.
64199
65−Source
66−------
200+#### Source
67201
68202 ++ homo :: homogenize
69− |* a/(list)
203+ |* a=(list)
70204 ^+ =< $
71205 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
72206 --
73207 a
74208
75209
76−Examples
77−--------
210+#### Examples
78211
79212 > lyst
80213 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
@@ -93,24 +226,21 @@ Examples
93226
94227List length
95228
96−Produces the length of any `++list` `a` as an atom.
229+Produces the length of any `list` `a` as an atom.
97230
98−Accepts
99−-------
231+#### Accepts
100232
101−`a` is a list.
233+`a` is a `list`.
102234
103−Produces
104−--------
235+#### Produces
105236
106237an atom.
107238
108−Source
109−------
239+#### Source
110240
111241 ++ lent :: length
112242 ~/ %lent
113− |= a/(list)
243+ |= a=(list)
114244 ^- @
115245 =+ b=0
116246 |-
@@ -118,120 +248,13 @@ Source
118248 $(a t.a, b +(b))
119249
120250
121−Examples
122−--------
251+#### Examples
123252
124− > (lent (limo [1 2 3 4 ~]))
253+ > (lent [1 2 3 4 ~]))
125254 4
126− > (lent (limo [1 'a' 2 'b' (some 10) ~]))
127− 5
128−
129−
130−
131−***
132−### `++find`
133−
134−First index in list
135−
136−Produces the index of the first occurrence of `++list` `nedl` in
137−`++list` `hstk` as the `++unit` of an atom.
138−
139−Accepts
140−-------
141−
142−`nedl` is a list.
143−
144−`hstk` is a list.
145−
146−Produces
147−--------
148−
149−The `++unit` of an atom.
150−
151−Source
152−------
153−
154− ++ find :: first index
155− ~/ %find
156− |= {nedl/(list) hstk/(list)}
157− =| i/@ud
158− |- ^- (unit @ud)
159− =+ [n=nedl h=hstk]
160− |-
161− ?: |(?=($~ n) ?=($~ h))
162− ~
163− ?: =(i.n i.h)
164− ?~ t.n
165− `i
166− $(n t.n, h t.h)
167− ^$(i +(i), hstk +.hstk)
168−
169−
170−Examples
171−--------
172−
173− > (find [3]~ ~[1 2 3])
174− [~ 2]
175− > (find [4]~ ~[1 2 3])
176− ~
177− > (find ['a']~ "cbabab")
178− [~ 2]
179− > (find "ab" "cbabab")
180− [~ 2]
181−
182−
183−
184−***
185−### `++fand`
186255
187−All indices in list
188−
189−Produces the indices of all occurrences of `++list` `nedl` in
190−`++list` `hstk` as a `++list` of atoms.
191−
192−Accepts
193−-------
194−
195−`nedl` is a list.
196−
197−`hstk` is a list.
198−
199−Produces
200−--------
201−
202−A `++list` of atoms.
203−
204−Source
205−------
206−
207− ++ fand :: all indices
208− ~/ %fand
209− |= {nedl/(list) hstk/(list)}
210− =| i/@ud
211− =| fnd/(list @ud)
212− |- ^+ fnd
213− =+ [n=nedl h=hstk]
214− |-
215− ?: |(?=($~ n) ?=($~ h))
216− (flop fnd)
217− ?: =(i.n i.h)
218− ?~ t.n
219− ^$(i +(i), hstk +.hstk, fnd [i fnd])
220− $(n t.n, h t.h)
221− ^$(i +(i), hstk +.hstk)
222−
223−
224−Examples
225−--------
226−
227− > (fand [3]~ ~[1 2 3])
228− ~[2]
229− > (fand [4]~ ~[1 2 3])
230− ~
231− > (fand ['a']~ "cbabab")
232− ~[2 4]
233− > (fand "ab" "cbabab")
234− ~[2 4]
256+ > (lent [1 'a' 2 'b' (some 10) ~])
257+ 5
235258
236259
237260
@@ -240,40 +263,37 @@ Examples
240263
241264Logical "and" on list
242265
243−Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `++list` `a`.
266+Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `list` `a`.
244267
245−Accepts
246−-------
268+#### Accepts
247269
248270`a` is a list.
249271
250272`b` is a gate.
251273
252−Produces
253−--------
274+#### Produces
254275
255276A boolean.
256277
257−Source
258−------
278+#### Source
259279
260280 ++ levy
261281 ~/ %levy :: all of
262− |* {a/(list) b/$-(* ?)}
282+ |* [a=(list) b=$-(* ?)]
263283 |- ^- ?
264284 ?~ a &
265285 ?. (b i.a) |
266286 $(a t.a)
267287
268288
269−Examples
270−--------
289+#### Examples
271290
272− > =a |=(a/@ (lte a 1))
273− > (levy (limo [0 1 2 1 ~]) a)
291+ > =a |=(a=@ (lte a 1))
292+ > (levy `(list @)`[0 1 2 1 ~] a)
274293 %.n
275− > =a |=(a/@ (lte a 3))
276− > (levy (limo [0 1 2 1 ~]) a)
294+
295+ > =a |=(a=@ (lte a 3))
296+ > (levy `(list @)`[0 1 2 1 ~] a)
277297 %.y
278298
279299
@@ -283,34 +303,32 @@ Examples
283303
284304Logical "or" on list
285305
286−Computes the Boolean logical "or" on the results of applying [gate]() `b` to every element of [`++list`]() `a`.
306+Computes the Boolean logical "or" on the results of applying `gate` `b` to
307+every element of `++list` `a`.
287308
288−Accepts
289−-------
309+#### Accepts
290310
291311`a` is a list.
292312
293313`b` is a gate.
294314
295−Source
296−------
315+#### Source
297316
298317 ++ lien :: some of
299318 ~/ %lien
300− |* {a/(list) b/$-(* ?)}
319+ |* [a=(list) b=$-(* ?)]
301320 |- ^- ?
302321 ?~ a |
303322 ?: (b i.a) &
304323 $(a t.a)
305−
306−Examples
307−--------
324+
325+#### Examples
308326
309327 > =a |=(a=@ (gte a 1))
310− > (lien (limo [0 1 2 1 ~]) a)
328+ > (lien `(list @)`[0 1 2 1 ~] a)
311329 %.y
312330 > =a |=(a=@ (gte a 3))
313− > (lien (limo [0 1 2 1 ~]) a)
331+ > (lien `(list @)`[0 1 2 1 ~]) a)
314332 %.n
315333
316334
@@ -320,20 +338,17 @@ Examples
320338
321339List Constructor
322340
323−Turns a null-terminated tuple into a [`++list`]().
341+Turns a null-terminated tuple into a `list`.
324342
325−Accepts
326−-------
343+#### Accepts
327344
328345`a` is a null-terminated tuple.
329346
330−Produces
331−--------
347+#### Produces
332348
333349A `++list`.
334350
335−Source
336−------
351+#### Source
337352
338353 ++ limo :: listify
339354 |* a=*
@@ -342,8 +357,7 @@ Source
342357 --
343358 a
344359
345−Examples
346−--------
360+#### Examples
347361
348362 > (limo [1 2 3 ~])
349363 [i=1 t=[i=2 t=[i=3 t=~]]]
@@ -355,28 +369,25 @@ Examples
355369
356370Maybe transform
357371
358−Passes each member of `++list` `a` to gate `b`, which must produce a
359−`++unit`. Produces a new list with all the results that do not produce
372+Passes each member of `list` `a` to gate `b`, which must produce a
373+`unit`. Produces a new list with all the results that do not produce
360374`~`.
361375
362−Accepts
363−-------
376+#### Accepts
364377
365378`a` is a list.
366379
367380`b` is a gate that produces a unit.
368381
369−Produces
370−--------
382+#### Produces
371383
372384A unit.
373385
374−Source
375−------
386+#### Source
376387
377388 ++ murn :: maybe transform
378389 ~/ %murn
379− |* {a/(list) b/$-(* (unit))}
390+ |* [a=(list) b=$-(* (unit))]
380391 |-
381392 ?~ a ~
382393 =+ c=(b i.a)
@@ -384,11 +395,10 @@ Source
384395 $(a t.a)
385396 [i=u.c t=$(a t.a)]
386397
387−Examples
388−--------
398+#### Examples
389399
390400 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
391− > (murn (limo [0 1 2 3 ~]) a)
401+ > (murn `(list @)`[0 1 2 3 ~] a)
392402 [i=12 t=[i=13 t=~]]
393403
394404
@@ -398,33 +408,31 @@ Examples
398408
399409Remove
400410
401−Removes elements from list `c` beginning at inclusive index `a`, removing `b` number of elements.
411+Removes elements from list `c` beginning at inclusive index `a`, removing `b`
412+number of elements.
402413
403−Accepts
404−-------
414+#### Accepts
405415
406416`c` is a list.
407417
408−Produces
409−--------
418+#### Produces
410419
411420A `++list`.
412421
413−Source
414−------
422+#### Source
415423
416424 ++ oust :: remove
417425 ~/ %oust
418− |* {{a/@ b/@} c/(list)}
426+ |* [[a=@ b=@] c=(list)]
419427 (weld (scag a c) (slag (add a b) c))
420428
421−Examples
422−--------
429+#### Examples
423430
424431 > (oust [4 5] "good day, urbit!")
425432 "good urbit!"
426− > (oust [2 2] (limo [1 2 3 4 ~]))
427− [i=1 t=[i=2 t=~]]
433+
434+ > (oust [2 2] `(list @)`[1 2 3 4 ~])
435+ ~[1 2]
428436
429437
430438
@@ -433,35 +441,35 @@ Examples
433441
434442Replicate
435443
436−Replicate: produces a `++list` containing `a` copies of `b`.
444+Replicate: produces a `list` containing `a` copies of `b`.
445+
446+#### Accepts
437447
438−Accepts
439−-------
448+`a` is an atom.
440449
441450`b` is a noun.
442451
443−Produces
444−--------
452+#### Produces
445453
446−A list.
454+A list.
447455
448−Source
449−------
456+#### Source
450457
451458 ++ reap :: replicate
452459 ~/ %reap
453− |* {a/@ b/*}
460+ |* [a=@ b=*]
454461 |- ^- (list _b)
455462 ?~ a ~
456463 [b $(a (dec a))]
457464
458−Examples
459−--------
465+#### Examples
460466
461467 > (reap 20 %a)
462468 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
469+
463470 > (reap 5 ~s1)
464471 ~[~s1 ~s1 ~s1 ~s1 ~s1]
472+
465473 > `@dr`(roll (reap 5 ~s1) add)
466474 ~s5
467475
@@ -472,41 +480,44 @@ Examples
472480
473481Right fold
474482
475−Right fold: moves right to left across a `++list` `a`, recursively slamming
483+Right fold: moves right to left across a `list` `a`, recursively slamming
476484a binary gate `b` with an element from `a` and an accumulator, producing
477485the final value of the accumulator.
478486
479−Accepts
480−-------
487+(To "slam" means to call a gate and give it a sample/samples. In this instance,
488+`a` is the list of samples that are given to the gate b.)
489+
490+#### Accepts
491+
492+`a` is a list.
481493
482494`b` is a binary gate.
483495
484−Produces
485−--------
496+#### Produces
486497
487498The accumulator, which is a noun.
488499
489−Source
490−------
500+#### Source
491501
492502 ++ reel :: right fold
493503 ~/ %reel
494− |* {a/(list) b/_|=({* *} +<+)}
504+ |* [a=(list) b=_|=([* *] +<+)]
495505 |- ^+ +<+.b
496506 ?~ a
497507 +<+.b
498508 (b i.a $(a t.a))
499509
500510
501−Examples
502−--------
511+#### Examples
503512
504513 > =sum =|([p=@ q=@] |.((add p q)))
505514 > (reel (limo [1 2 3 4 5 ~]) sum)
506515 15
516+
507517 > =a =|([p=@ q=@] |.((sub p q)))
508518 > (reel (limo [6 3 1 ~]) a)
509519 4
520+
510521 > (reel (limo [3 6 1 ~]) a)
511522 ! subtract-underflow
512523 ! exit
@@ -519,21 +530,23 @@ Examples
519530Left fold
520531
521532Left fold: moves left to right across a list `a`, recursively slamming a
522−binary [gate]() `b` with an element from the [`++list`]() and an accumulator,
533+binary gate `b` with an element from the `list` and an accumulator,
523534producing the final value of the accumulator.
524535
525−Accepts
526−-------
536+(To "slam" means to call a gate and give it a sample/samples. In this instance,
537+`a` is the list of samples that are given to the gate b.)
538+
539+#### Accepts
527540
528−`b` is a binary [gate]().
541+`a` is a list.
542+
543+`b` is a binary gate.
529544
530−Produces
531−--------
545+#### Produces
532546
533−The accumulator, which is a [noun]().
547+The accumulator, which is a noun.
534548
535−Source
536−------
549+#### Source
537550
538551 ++ roll :: left fold
539552 ~/ %roll
@@ -543,8 +556,7 @@ Source
543556 +<+.b
544557 $(a t.a, b b(+<+ (b i.a +<+.b)))
545558
546−Examples
547−--------
559+#### Examples
548560
549561 > =sum =|([p=@ q=@] |.((add p q)))
550562 > (roll (limo [1 2 3 4 5 ~]) sum)
@@ -563,21 +575,20 @@ Examples
563575
564576Prefix
565577
566−Accepts an atom `a` and [list]() `b`, producing the first `a` elements of
578+Accepts an atom `a` and `list` `b`, producing the first `a` elements of
567579the front of the list.
568580
569−Accepts
570−-------
581+#### Accepts
582+
583+`a` is an atom.
571584
572585`b` is a list.
573586
574−Produces
575−--------
587+#### Produces
576588
577589A list of the same type as `b`.
578590
579−Source
580−------
591+#### Source
581592
582593 ++ scag :: prefix
583594 ~/ %scag
@@ -586,13 +597,13 @@ Source
586597 ?: |(?=(~ b) =(0 a)) ~
587598 [i.b $(b t.b, a (dec a))]
588599
589−Examples
590−--------
600+#### Examples
591601
592− > (scag 2 (limo [0 1 2 3 ~]))
593− [i=0 t=[i=1 t=~]]
594− > (scag 10 (limo [1 2 3 4 ~]))
595− [i=1 t=[i=2 t=[i=3 t=[i=4 t=~]]]]
602+ > (scag 2 `(list @)`[1 2 3 4 ~])
603+ [i=0 t=~[1]]
604+
605+ > (scag 10 `(list @)`[1 2 3 4 ~])
606+ [i=1 t=~[2 3 4]]
596607
597608
598609
@@ -601,25 +612,27 @@ Examples
601612
602613Separate
603614
604−Separates a `++list` `a` into two lists - Those elements of `a` who produce
615+Separates a `list` `a` into two lists - Those elements of `a` who produce
605616true when slammed to gate `b` and those who produce `%.n`.
606617
607−Accepts
608−-------
618+(To "slam" means to call a gate and give it a sample/samples. In this instance,
619+`a` is the list of samples that are given to the gate `b`.)
620+
621+#### Accepts
609622
610−`b` is a gate that accepts one argument and produces a loobean.
623+`a` is a list.
624+
625+`b` is a gate that accepts one argument and produces a flag.
611626
612−Produces
613−--------
627+#### Produces
614628
615629A cell of two lists.
616630
617−Source
618−------
631+#### Source
619632
620633 ++ skid :: separate
621634 ~/ %skid
622− |* {a/(list) b/$-(* ?)}
635+ |* [a=(list) b=$-(* ?)]
623636 |- ^+ [p=a q=a]
624637 ?~ a [~ ~]
625638 =+ c=$(a t.a)
@@ -627,12 +640,11 @@ Source
627640
628641
629642
630−Examples
631−--------
643+#### Examples
632644
633− > =a |=(a/@ (gth a 1))
634− > (skid (limo [0 1 2 3 ~]) a)
635− [p=[i=2 t=[i=3 t=~]] q=[i=0 t=[i=1 t=~]]]
645+ > =a |=(a=@ (gth a 1))
646+ > (skid `(list @)`[0 1 2 3 ~]) a)
647+ (skid `(list @)`[0 1 2 3 ~]) a)
636648
637649
638650
@@ -643,36 +655,34 @@ Suffix
643655
644656Cycles through the members of a list `a`, passing them to a gate `b` and
645657producing a list of all of the members that produce `%.y`. Inverse of
646−`++skip`.
658+`skip`.
647659
648−Accepts
649−-------
660+#### Accepts
661+
662+`a` is a list.
650663
651664`b` is a gate that accepts one argument and produces a boolean.
652665
653−Produces
654−--------
666+#### Produces
655667
656−A boolean
668+A flag.
657669
658−Source
659−------
670+#### Source
660671
661672 ++ skim :: only
662673 ~/ %skim
663− |* {a/(list) b/$-(* ?)}
674+ |* [a=(list) b=$-(* ?)]
664675 |-
665676 ^+ a
666677 ?~ a ~
667678 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
668679
669680
670−Examples
671−--------
681+#### Examples
672682
673− > =a |=(a/@ (gth a 1))
674− > (skim (limo [0 1 2 3 ~]) a)
675− [i=2 t=[i=3 t=~]]
683+ > =a |=(a=@ (gth a 1))
684+ > (skim `(list @)`[0 1 2 3 ~] a)
685+ [i=2 t=~[3]]
676686
677687
678688
@@ -681,37 +691,35 @@ Examples
681691
682692Except
683693
684−Cycles through the members of `++list` `a`, passing them to a gate `b`.
694+Cycles through the members of `list` `a`, passing them to a gate `b`.
685695Produces a list of all of the members that produce `%.n`. Inverse of
686−`++skim`.
696+`skim`.
697+
698+#### Accepts
687699
688−Accepts
689−-------
700+`a` is a list.
690701
691−`b` is a gate that accepts one argument and produces a loobean.
702+`b` is a gate that accepts one argument and produces a flag.
692703
693−Produces
694−--------
704+#### Produces
695705
696706A list of the same type as `a`.
697707
698−Source
699−------
708+#### Source
700709
701710 ++ skip :: except
702711 ~/ %skip
703− |* {a/(list) b/$-(* ?)}
712+ |* [a=(list) b=$-(* ?)]
704713 |-
705714 ^+ a
706715 ?~ a ~
707716 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
708717
709718
710−Examples
711−--------
719+#### Examples
712720
713− > =a |=(a/@ (gth a 1))
714− > (skip (limo [0 1 2 3 ~]) a)
721+ > =a |=(a=@ (gth a 1))
722+ > (skip `(l)`[0 1 2 3 ~]) a)
715723 [i=0 t=[i=1 t=~]]
716724
717725
@@ -724,30 +732,26 @@ Suffix
724732Accepts an atom `a` and list `b`, producing the remaining elements from
725733`b` starting at `a`.
726734
727−Accepts
728−-------
735+#### Accepts
729736
730737`b` is a list.
731738
732−Produces
733−--------
739+#### Produces
734740
735741A list of the same type as `b`.
736742
737−Source
738−------
743+#### Source
739744
740745 ++ slag :: suffix
741746 ~/ %slag
742− |* {a/@ b/(list)}
747+ |* [a=@ b=(list)]
743748 |- ^+ b
744749 ?: =(0 a) b
745750 ?~ b ~
746751 $(b t.b, a (dec a))
747752
748753
749−Examples
750−--------
754+#### Examples
751755
752756 > (slag 2 (limo [1 2 3 4 ~]))
753757 [i=3 t=[i=4 t=~]]
@@ -764,22 +768,19 @@ Index
764768Accepts an atom `a` and a `++list` `b`, producing the element at the index
765769of `a`and failing if the list is null. Lists are 0-indexed.
766770
767−Accepts
768−-------
771+#### Accepts
769772
770773`b` is a list.
771774
772−Produces
773−--------
775+#### Produces
774776
775777Produces an element of `b`, or crashes if no element exists at that index.
776778
777−Source
778−------
779+#### Source
779780
780781 ++ snag :: index
781782 ~/ %snag
782− |* {a/@ b/(list)}
783+ |* [a=@ b=(list)]
783784 |-
784785 ?~ b
785786 ~|('snag-fail' !!)
@@ -787,8 +788,7 @@ Source
787788 $(b t.b, a (dec a))
788789
789790
790−Examples
791−--------
791+#### Examples
792792
793793 > (snag 2 "asdf")
794794 ~~d
@@ -803,25 +803,22 @@ Examples
803803Quicksort
804804
805805Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
806−produces a loobean. `++sort` then produces a list of the elements of `a`,
806+produces a flag. `++sort` then produces a list of the elements of `a`,
807807sorted according to `b`.
808808
809−Accepts
810−-------
809+#### Accepts
811810
812811`b` is a gate that accepts two nouns and produces a boolean.
813812
814−Produces
815−--------
813+#### Produces
816814
817815A list
818816
819−Source
820−------
817+#### Source
821818
822819 ++ sort !. :: quicksort
823820 ~/ %sort
824− |* {a/(list) b/$-([* *] ?)}
821+ |* [a=(list) b=$-([* *] ?)]
825822 => .(a ^.(homo a))
826823 |- ^+ a
827824 ?~ a ~
@@ -831,91 +828,14 @@ Source
831828 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
832829
833830
834−Examples
835−--------
831+#### Examples
836832
837− > =a =|({p/@ q/@} |.((gth p q)))
833+ > =a =|([p/@ q/@] |.((gth p q)))
838834 > (sort (limo [0 1 2 3 ~]) a)
839835 ~[3 2 1 0]
840836
841837
842838
843−***
844−### `++swag`
845−
846−Infix
847−
848−Similar to `substr` in Javascript: extracts a string infix, beginning at
849−inclusive index `a`, producing `b` number of characters.
850−
851−Accepts
852−-------
853−
854−`c` is a list.
855−
856−Produces
857−--------
858−
859−A list of the same type as `c`.
860−
861−Source
862−------
863−
864− ++ swag :: infix
865− |* {{a/@ b/@} c/(list)}
866− (scag +<-> (slag +<-< c))
867−
868−
869−Examples
870−--------
871−
872− > (swag [2 5] "roly poly")
873− "ly po"
874− > (swag [2 2] (limo [1 2 3 4 ~]))
875− [i=3 t=[i=4 t=~]]
876−
877−
878−
879−***
880−### `++turn`
881−
882−Gate to list
883−
884−Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
885−to each element of the original list.
886−
887−Accepts
888−-------
889−
890−`b` is a gate.
891−
892−Produces
893−--------
894−
895−A list.
896−
897−Source
898−------
899−
900− ++ turn :: transform
901− ~/ %turn
902− |* {a/(list) b/gate}
903− |-
904− ?~ a ~
905− [i=(b i.a) t=$(a t.a)]
906−
907−
908−Examples
909−--------
910−
911− > (turn (limo [104 111 111 110 ~]) @t)
912− <|h o o n|>
913− > =a |=(a/@ (add a 4))
914− > (turn (limo [1 2 3 4 ~]) a)
915− ~[5 6 7 8]
916−
917−
918−
919839***
920840### `++spin`
921841
@@ -927,8 +847,7 @@ a tuple -- the head is an element of `a` and the tail is the state `c`, and
927847should produce a tuple of the transformed element and the (potentially
928848modified) state `c`.
929849
930−Accepts
931−-------
850+#### Accepts
932851
933852`a` is a `++list`.
934853
@@ -936,16 +855,14 @@ Accepts
936855
937856`c` is a noun.
938857
939−Produces
940−--------
858+#### Produces
941859
942860A list.
943861
944−Source
945−------
862+#### Source
946863
947864 ++ spin
948− |* {a/(list) b/_|=({* *} [** +<+]) c/*}
865+ |* [a=(list) b=_|=([* *] [** +<+]) c/*]
949866 :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
950867 |-
951868 ?~ a
@@ -954,31 +871,25 @@ Source
954871 [i=-.v t=$(a t.a, c +.v)]
955872
956873
957−Examples
958−--------
874+#### Examples
959875
960−A trivial example -- does nothing with the state:
961876
962− > %^ spin (limo ~[4 5 6])
963− |=({n/@ a/@} [n a])
877+ > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
878+ |=([n=@ a=@] [n a])
964879 0
965880 ~[4 5 6]
966881
967−Create a list of pairs, `p` as the index and `q` as the list element:
968−
969− > %^ spin (limo ~[4 5 6])
970− |=({n/@ a/@} [`(pair)`[a n] +(a)])
882+ > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
883+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
971884 0
972885 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
973886
974−Create 10 random numbers less than `10`:
975−
976− > %^ spin (reap 10 0)
977− |=({n/@ rng/_og} (rads:rng 10))
887+ > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
888+ |=([n=@ rng=_og] (rads:rng 10))
978889 ~(. og eny)
979890 ~[5 5 9 4 1 7 9 9 9 6]
980891
981−*Notes*:
892+#### Discussion
982893
983894`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
984895with entropy (`eny`). The head of the product is the random number, the tail
@@ -991,31 +902,27 @@ is the continuation of the RNG.
991902
992903Gate to list, with state
993904
994−Accepts a `++list` `a` and a gate `b`. `c` is internal state, initially
905+Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
995906derived by *bunting* the tail of the sample of gate `b`, instead of
996907being passed in explicitly as in `++spin`. Produces a list with the
997−gate applied to each element of the original list. `b` is called with a tuple
998−-- the head is an element of `a` and the tail is the state `c`, and should
908+gate applied to each element of the original list. `b` is called with a #### tuple the head is an element of `a` and the tail is the state `c`, and should
999909produce a tuple of the transformed element and the (potentially modified)
1000910state `c`.
1001911
1002−Accepts
1003−-------
912+#### Accepts
1004913
1005914`a` is a `++list`.
1006915
1007916`b` is a gate.
1008917
1009−Produces
1010−--------
918+#### Produces
1011919
1012920A list.
1013921
1014−Source
1015−------
922+#### Source
1016923
1017924 ++ spun
1018− |* {a/(list) b/_|=({* *} [** +<+])}
925+ |* [a=(list) b=_|=([* *] [** +<+])]
1019926 =| c/_+<+.b
1020927 |-
1021928 ?~ a
@@ -1024,24 +931,88 @@ Source
1024931 [i=-.v t=$(a t.a, c +.v)]
1025932
1026933
1027−Examples
1028−--------
934+#### Examples
1029935
1030−Create a list of pairs, `p` as the index and `q` as the list element:
1031−
1032− > %+ spun (limo ~[4 5 6])
1033− |=({n/@ a/@} [`(pair)`[a n] +(a)])
936+ > %+ spun (limo ~[4 5 6]) ::`p` as the index and `q` as the list element
937+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
1034938 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1035939
1036−Join two lists into a list of pairs, `p` from `l` and `q` from the sample:
1037−
1038− > =l (limo ~[7 8 9])
940+ > =l (limo ~[7 8 9]) ::joins two lists into a list of pairs
1039941 > %+ spun (limo ~[4 5 6])
1040− |=({n/@ a/@} [`(pair)`[(snag a l) n] +(a)])
942+ |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1041943 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1042944
1043945
1044946
947+***
948+### `++swag`
949+
950+Infix
951+
952+Similar to `substr` in Javascript: extracts a string infix, beginning at
953+inclusive index `a`, producing `b` number of characters.
954+
955+#### Accepts
956+
957+`c` is a list.
958+
959+#### Produces
960+
961+A list of the same type as `c`.
962+
963+#### Source
964+
965+ ++ swag
966+ |* [[a=@ a=@] c=(list)]
967+ (scag +<-> (slag +<-< c))
968+
969+
970+#### Examples
971+
972+ > (swag [2 5] "roly poly")
973+ "ly po"
974+ > (swag [2 2] (limo [1 2 3 4 ~]))
975+ [i=3 t=[i=4 t=~]]
976+
977+
978+
979+***
980+### `++turn`
981+
982+Gate to list
983+
984+Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
985+to each element of the original list.
986+
987+#### Accepts
988+
989+`b` is a gate.
990+
991+#### Produces
992+
993+A list.
994+
995+#### Source
996+
997+ ++ turn
998+ ~/ %turn
999+ |* [a=(list) b=gate]
1000+ |-
1001+ ?~ a ~
1002+ [i=(b i.a) t=$(a t.a)]
1003+
1004+
1005+#### Examples
1006+
1007+ > (turn (limo [104 111 111 110 ~]) @t)
1008+ <|h o o n|>
1009+
1010+ > =a |=(a=@ (add a 4))
1011+ > (turn (limo [1 2 3 4 ~]) a)
1012+ ~[5 6 7 8]
1013+
1014+
1015+
10451016***
10461017### `++weld`
10471018
@@ -1049,25 +1020,22 @@ Concatenate
10491020
10501021Concatenate two `++list`s `a` and `b`.
10511022
1052−Accepts
1053−-------
1023+#### Accepts
10541024
10551025`a` and `b` are lists.
10561026
1057−Source
1058−------
1027+#### Source
10591028
1060− ++ weld :: concatenate
1029+ ++ weld
10611030 ~/ %weld
1062− |* {a/(list) b/(list)}
1031+ |* [a=(list) b=(list)]
10631032 => .(a ^.(homo a), b ^.(homo b))
10641033 |- ^+ b
10651034 ?~ a b
10661035 [i.a $(a t.a)]
10671036
10681037
1069−Examples
1070−--------
1038+#### Examples
10711039
10721040 > (weld "urb" "it")
10731041 ~[~~u ~~r ~~b ~~i ~~t]
@@ -1084,23 +1052,20 @@ Perfect weld
10841052Concatenate two `++list`s `a` and `b` without losing their type information
10851053to homogenization.
10861054
1087−Accepts
1088−-------
1055+#### Accepts
10891056
10901057`a` is a list.
10911058
10921059`b` is a list.
10931060
1094−Produces
1095−--------
1061+#### Produces
10961062
10971063A list.
10981064
1099−Source
1100−------
1065+#### Source
11011066
1102− ++ welp :: perfect weld
1103− =| {* *}
1067+ ++ welp
1068+ =| [* *]
11041069 |%
11051070 +- $
11061071 ?~ +<-
@@ -1109,8 +1074,7 @@ Source
11091074 --
11101075
11111076
1112−Examples
1113−--------
1077+#### Examples
11141078
11151079 > (welp "foo" "bar")
11161080 "foobar"
@@ -1119,7 +1083,7 @@ Examples
11191083 ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
11201084 [60 61 62 %a %b %c ~]
11211085 [@ud @ud @ud %a %b %c %~]
1122− ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si/3)
1086+ ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si=3)
11231087 [[%sa 1] [%so 2] %si 3]
11241088
11251089
@@ -1132,20 +1096,17 @@ Cons
11321096Turns a `++list` of lists into a single list by promoting the elements of
11331097each sublist into the higher.
11341098
1135−Accepts
1136−-------
1099+#### Accepts
11371100
11381101A list of lists.
11391102
1140−Produces
1141−--------
1103+#### Produces
11421104
11431105A list.
11441106
1145−Source
1146−------
1107+#### Source
11471108
1148− ++ zing :: promote
1109+ ++ zing
11491110 =| *
11501111 |%
11511112 +- $
@@ -1156,11 +1117,11 @@ Source
11561117
11571118
11581119
1159−Examples
1160−--------
1120+#### Examples
11611121
11621122 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
11631123 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1124+
11641125 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
11651126 ~[1 97 2 98 3 99 4 100]
11661127