@@ -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 `nedl` in `hstk` as a `list` of
12+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
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 `nedl` in `hstk` as the `unit`
65+of an atom.
66+
67+#### Accepts
868
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
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]
108+
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
22125
23−Source
24−------
126+A `list`.
25127
26− ++ flop :: reverse
128+#### Source
129+
130+ ++ flop
27131 ~/ %flop
28− |* a/(list)
132+ |* a=(list)
29133 => .(a (homo a))
30134 ^+ a
31135 =+ b=`_a`~
@@ -35,54 +139,87 @@ 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`
45153
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.
162+
163+`b` is an atom.
164+
165+#### Produces
166+
167+a `list`.
168+
169+#### Source
170+
171+ ++ gulf
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
53−list `a`. Used when you want to make all the types of the elements of a list the same.
189+Produces a `list` whose type is a fork of all the contained types in the
190+list `a`. Used when you want to make all the types of the elements of a list the
191+ same.
54192
55−Accepts
56−-------
193+#### Accepts
57194
58−`a` is a list.
195+`a` is a `list`.
59196
60−Produces
61−--------
197+#### Produces
62198
63−a list.
199+a `list`.
64200
65−Source
66−------
201+#### Source
67202
68− ++ homo :: homogenize
69− |* a/(list)
203+ ++ homo
204+ |* a=(list)
70205 ^+ =< $
71206 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
72207 --
73208 a
74209
75210
76−Examples
77−--------
211+#### Examples
78212
79213 > lyst
80214 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
215+
81216 > (homo lyst)
82217 ~[1 97 2 98 [~ u=10]]
218+
83219 > =a (limo [1 2 3 ~])
84220 > a
85221 [i=1 t=[i=2 t=[i=3 t=~]]]
222+
86223 > (homo a)
87224 ~[1 2 3]
88225
@@ -93,24 +230,21 @@ Examples
93230
94231List length
95232
96−Produces the length of any `++list` `a` as an atom.
233+Produces the length of any `list` `a` as an atom.
97234
98−Accepts
99−-------
235+#### Accepts
100236
101−`a` is a list.
237+`a` is a `list`.
102238
103−Produces
104−--------
239+#### Produces
105240
106241an atom.
107242
108−Source
109−------
243+#### Source
110244
111− ++ lent :: length
245+ ++ lent
112246 ~/ %lent
113− |= a/(list)
247+ |= a=(list)
114248 ^- @
115249 =+ b=0
116250 |-
@@ -118,120 +252,13 @@ Source
118252 $(a t.a, b +(b))
119253
120254
121−Examples
122−--------
255+#### Examples
123256
124− > (lent (limo [1 2 3 4 ~]))
257+ > (lent [1 2 3 4 ~]))
125258 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`
186−
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−--------
226259
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]
260+ > (lent [1 'a' 2 'b' (some 10) ~])
261+ 5
235262
236263
237264
@@ -240,40 +267,37 @@ Examples
240267
241268Logical "and" on list
242269
243−Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `++list` `a`.
270+Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `list` `a`.
244271
245−Accepts
246−-------
272+#### Accepts
247273
248274`a` is a list.
249275
250276`b` is a gate.
251277
252−Produces
253−--------
278+#### Produces
254279
255280A boolean.
256281
257−Source
258−------
282+#### Source
259283
260284 ++ levy
261285 ~/ %levy :: all of
262− |* {a/(list) b/$-(* ?)}
286+ |* [a=(list) b=$-(* ?)]
263287 |- ^- ?
264288 ?~ a &
265289 ?. (b i.a) |
266290 $(a t.a)
267291
268292
269−Examples
270−--------
293+#### Examples
271294
272− > =a |=(a/@ (lte a 1))
273− > (levy (limo [0 1 2 1 ~]) a)
295+ > =a |=(a=@ (lte a 1))
296+ > (levy `(list @)`[0 1 2 1 ~] a)
274297 %.n
275− > =a |=(a/@ (lte a 3))
276− > (levy (limo [0 1 2 1 ~]) a)
298+
299+ > =a |=(a=@ (lte a 3))
300+ > (levy `(list @)`[0 1 2 1 ~] a)
277301 %.y
278302
279303
@@ -283,34 +307,33 @@ Examples
283307
284308Logical "or" on list
285309
286−Computes the Boolean logical "or" on the results of applying [gate]() `b` to every element of [`++list`]() `a`.
310+Computes the Boolean logical "or" on the results of applying `gate` `b` to
311+every element of `++list` `a`.
287312
288−Accepts
289−-------
313+#### Accepts
290314
291315`a` is a list.
292316
293317`b` is a gate.
294318
295−Source
296−------
319+#### Source
297320
298− ++ lien :: some of
321+ ++ lien
299322 ~/ %lien
300− |* {a/(list) b/$-(* ?)}
323+ |* [a=(list) b=$-(* ?)]
301324 |- ^- ?
302325 ?~ a |
303326 ?: (b i.a) &
304327 $(a t.a)
305−
306−Examples
307−--------
328+
329+#### Examples
308330
309331 > =a |=(a=@ (gte a 1))
310− > (lien (limo [0 1 2 1 ~]) a)
332+ > (lien `(list @)`[0 1 2 1 ~] a)
311333 %.y
334+
312335 > =a |=(a=@ (gte a 3))
313− > (lien (limo [0 1 2 1 ~]) a)
336+ > (lien `(list @)`[0 1 2 1 ~]) a)
314337 %.n
315338
316339
@@ -320,20 +343,17 @@ Examples
320343
321344List Constructor
322345
323−Turns a null-terminated tuple into a [`++list`]().
346+Turns a null-terminated tuple into a `list`.
324347
325−Accepts
326−-------
348+#### Accepts
327349
328350`a` is a null-terminated tuple.
329351
330−Produces
331−--------
352+#### Produces
332353
333354A `++list`.
334355
335−Source
336−------
356+#### Source
337357
338358 ++ limo :: listify
339359 |* a=*
@@ -342,8 +362,7 @@ Source
342362 --
343363 a
344364
345−Examples
346−--------
365+#### Examples
347366
348367 > (limo [1 2 3 ~])
349368 [i=1 t=[i=2 t=[i=3 t=~]]]
@@ -355,28 +374,25 @@ Examples
355374
356375Maybe transform
357376
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
377+Passes each member of `list` `a` to gate `b`, which must produce a
378+`unit`. Produces a new list with all the results that do not produce
360379`~`.
361380
362−Accepts
363−-------
381+#### Accepts
364382
365383`a` is a list.
366384
367385`b` is a gate that produces a unit.
368386
369−Produces
370−--------
387+#### Produces
371388
372389A unit.
373390
374−Source
375−------
391+#### Source
376392
377393 ++ murn :: maybe transform
378394 ~/ %murn
379− |* {a/(list) b/$-(* (unit))}
395+ |* [a=(list) b=$-(* (unit))]
380396 |-
381397 ?~ a ~
382398 =+ c=(b i.a)
@@ -384,11 +400,10 @@ Source
384400 $(a t.a)
385401 [i=u.c t=$(a t.a)]
386402
387−Examples
388−--------
403+#### Examples
389404
390405 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
391− > (murn (limo [0 1 2 3 ~]) a)
406+ > (murn `(list @)`[0 1 2 3 ~] a)
392407 [i=12 t=[i=13 t=~]]
393408
394409
@@ -398,33 +413,31 @@ Examples
398413
399414Remove
400415
401−Removes elements from list `c` beginning at inclusive index `a`, removing `b` number of elements.
416+Removes elements from list `c` beginning at inclusive index `a`, removing `b`
417+number of elements.
402418
403−Accepts
404−-------
419+#### Accepts
405420
406421`c` is a list.
407422
408−Produces
409−--------
423+#### Produces
410424
411425A `++list`.
412426
413−Source
414−------
427+#### Source
415428
416429 ++ oust :: remove
417430 ~/ %oust
418− |* {{a/@ b/@} c/(list)}
431+ |* [[a=@ b=@] c=(list)]
419432 (weld (scag a c) (slag (add a b) c))
420433
421−Examples
422−--------
434+#### Examples
423435
424436 > (oust [4 5] "good day, urbit!")
425437 "good urbit!"
426− > (oust [2 2] (limo [1 2 3 4 ~]))
427− [i=1 t=[i=2 t=~]]
438+
439+ > (oust [2 2] `(list @)`[1 2 3 4 ~])
440+ ~[1 2]
428441
429442
430443
@@ -433,35 +446,35 @@ Examples
433446
434447Replicate
435448
436−Replicate: produces a `++list` containing `a` copies of `b`.
449+Replicate: produces a `list` containing `a` copies of `b`.
450+
451+#### Accepts
437452
438−Accepts
439−-------
453+`a` is an atom.
440454
441455`b` is a noun.
442456
443−Produces
444−--------
457+#### Produces
445458
446−A list.
459+A list.
447460
448−Source
449−------
461+#### Source
450462
451463 ++ reap :: replicate
452464 ~/ %reap
453− |* {a/@ b/*}
465+ |* [a=@ b=*]
454466 |- ^- (list _b)
455467 ?~ a ~
456468 [b $(a (dec a))]
457469
458−Examples
459−--------
470+#### Examples
460471
461472 > (reap 20 %a)
462473 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
474+
463475 > (reap 5 ~s1)
464476 ~[~s1 ~s1 ~s1 ~s1 ~s1]
477+
465478 > `@dr`(roll (reap 5 ~s1) add)
466479 ~s5
467480
@@ -472,41 +485,44 @@ Examples
472485
473486Right fold
474487
475−Right fold: moves right to left across a `++list` `a`, recursively slamming
488+Right fold: moves right to left across a `list` `a`, recursively slamming
476489a binary gate `b` with an element from `a` and an accumulator, producing
477490the final value of the accumulator.
478491
479−Accepts
480−-------
492+(To "slam" means to call a gate and give it a sample/samples. In this instance,
493+`a` is the list of samples that are given to the gate b.)
494+
495+#### Accepts
496+
497+`a` is a list.
481498
482499`b` is a binary gate.
483500
484−Produces
485−--------
501+#### Produces
486502
487503The accumulator, which is a noun.
488504
489−Source
490−------
505+#### Source
491506
492507 ++ reel :: right fold
493508 ~/ %reel
494− |* {a/(list) b/_|=({* *} +<+)}
509+ |* [a=(list) b=_|=([* *] +<+)]
495510 |- ^+ +<+.b
496511 ?~ a
497512 +<+.b
498513 (b i.a $(a t.a))
499514
500515
501−Examples
502−--------
516+#### Examples
503517
504518 > =sum =|([p=@ q=@] |.((add p q)))
505519 > (reel (limo [1 2 3 4 5 ~]) sum)
506520 15
521+
507522 > =a =|([p=@ q=@] |.((sub p q)))
508523 > (reel (limo [6 3 1 ~]) a)
509524 4
525+
510526 > (reel (limo [3 6 1 ~]) a)
511527 ! subtract-underflow
512528 ! exit
@@ -519,21 +535,23 @@ Examples
519535Left fold
520536
521537Left 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,
538+binary gate `b` with an element from the `list` and an accumulator,
523539producing the final value of the accumulator.
524540
525−Accepts
526−-------
541+(To "slam" means to call a gate and give it a sample/samples. In this instance,
542+`a` is the list of samples that are given to the gate b.)
543+
544+#### Accepts
527545
528−`b` is a binary [gate]().
546+`a` is a list.
529547
530−Produces
531−--------
548+`b` is a binary gate.
532549
533−The accumulator, which is a [noun]().
550+#### Produces
534551
535−Source
536−------
552+The accumulator, which is a noun.
553+
554+#### Source
537555
538556 ++ roll :: left fold
539557 ~/ %roll
@@ -543,8 +561,7 @@ Source
543561 +<+.b
544562 $(a t.a, b b(+<+ (b i.a +<+.b)))
545563
546−Examples
547−--------
564+#### Examples
548565
549566 > =sum =|([p=@ q=@] |.((add p q)))
550567 > (roll (limo [1 2 3 4 5 ~]) sum)
@@ -563,21 +580,20 @@ Examples
563580
564581Prefix
565582
566−Accepts an atom `a` and [list]() `b`, producing the first `a` elements of
583+Accepts an atom `a` and `list` `b`, producing the first `a` elements of
567584the front of the list.
568585
569−Accepts
570−-------
586+#### Accepts
587+
588+`a` is an atom.
571589
572590`b` is a list.
573591
574−Produces
575−--------
592+#### Produces
576593
577594A list of the same type as `b`.
578595
579−Source
580−------
596+#### Source
581597
582598 ++ scag :: prefix
583599 ~/ %scag
@@ -586,13 +602,13 @@ Source
586602 ?: |(?=(~ b) =(0 a)) ~
587603 [i.b $(b t.b, a (dec a))]
588604
589−Examples
590−--------
605+#### Examples
591606
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=~]]]]
607+ > (scag 2 `(list @)`[1 2 3 4 ~])
608+ [i=0 t=~[1]]
609+
610+ > (scag 10 `(list @)`[1 2 3 4 ~])
611+ [i=1 t=~[2 3 4]]
596612
597613
598614
@@ -601,25 +617,27 @@ Examples
601617
602618Separate
603619
604−Separates a `++list` `a` into two lists - Those elements of `a` who produce
620+Separates a `list` `a` into two lists - Those elements of `a` who produce
605621true when slammed to gate `b` and those who produce `%.n`.
606622
607−Accepts
608−-------
623+(To "slam" means to call a gate and give it a sample/samples. In this instance,
624+`a` is the list of samples that are given to the gate `b`.)
625+
626+#### Accepts
627+
628+`a` is a list.
609629
610−`b` is a gate that accepts one argument and produces a loobean.
630+`b` is a gate that accepts one argument and produces a flag.
611631
612−Produces
613−--------
632+#### Produces
614633
615634A cell of two lists.
616635
617−Source
618−------
636+#### Source
619637
620638 ++ skid :: separate
621639 ~/ %skid
622− |* {a/(list) b/$-(* ?)}
640+ |* [a=(list) b=$-(* ?)]
623641 |- ^+ [p=a q=a]
624642 ?~ a [~ ~]
625643 =+ c=$(a t.a)
@@ -627,12 +645,11 @@ Source
627645
628646
629647
630−Examples
631−--------
648+#### Examples
632649
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=~]]]
650+ > =a |=(a=@ (gth a 1))
651+ > (skid `(list @)`[0 1 2 3 ~]) a)
652+ (skid `(list @)`[0 1 2 3 ~]) a)
636653
637654
638655
@@ -643,36 +660,34 @@ Suffix
643660
644661Cycles through the members of a list `a`, passing them to a gate `b` and
645662producing a list of all of the members that produce `%.y`. Inverse of
646−`++skip`.
663+`skip`.
647664
648−Accepts
649−-------
665+#### Accepts
666+
667+`a` is a list.
650668
651669`b` is a gate that accepts one argument and produces a boolean.
652670
653−Produces
654−--------
671+#### Produces
655672
656−A boolean
673+A flag.
657674
658−Source
659−------
675+#### Source
660676
661677 ++ skim :: only
662678 ~/ %skim
663− |* {a/(list) b/$-(* ?)}
679+ |* [a=(list) b=$-(* ?)]
664680 |-
665681 ^+ a
666682 ?~ a ~
667683 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
668684
669685
670−Examples
671−--------
686+#### Examples
672687
673− > =a |=(a/@ (gth a 1))
674− > (skim (limo [0 1 2 3 ~]) a)
675− [i=2 t=[i=3 t=~]]
688+ > =a |=(a=@ (gth a 1))
689+ > (skim `(list @)`[0 1 2 3 ~] a)
690+ [i=2 t=~[3]]
676691
677692
678693
@@ -681,37 +696,35 @@ Examples
681696
682697Except
683698
684−Cycles through the members of `++list` `a`, passing them to a gate `b`.
699+Cycles through the members of `list` `a`, passing them to a gate `b`.
685700Produces a list of all of the members that produce `%.n`. Inverse of
686−`++skim`.
701+`skim`.
687702
688−Accepts
689−-------
703+#### Accepts
690704
691−`b` is a gate that accepts one argument and produces a loobean.
705+`a` is a list.
692706
693−Produces
694−--------
707+`b` is a gate that accepts one argument and produces a flag.
708+
709+#### Produces
695710
696711A list of the same type as `a`.
697712
698−Source
699−------
713+#### Source
700714
701715 ++ skip :: except
702716 ~/ %skip
703− |* {a/(list) b/$-(* ?)}
717+ |* [a=(list) b=$-(* ?)]
704718 |-
705719 ^+ a
706720 ?~ a ~
707721 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
708722
709723
710−Examples
711−--------
724+#### Examples
712725
713− > =a |=(a/@ (gth a 1))
714− > (skip (limo [0 1 2 3 ~]) a)
726+ > =a |=(a=@ (gth a 1))
727+ > (skip `(l)`[0 1 2 3 ~]) a)
715728 [i=0 t=[i=1 t=~]]
716729
717730
@@ -724,30 +737,26 @@ Suffix
724737Accepts an atom `a` and list `b`, producing the remaining elements from
725738`b` starting at `a`.
726739
727−Accepts
728−-------
740+#### Accepts
729741
730742`b` is a list.
731743
732−Produces
733−--------
744+#### Produces
734745
735746A list of the same type as `b`.
736747
737−Source
738−------
748+#### Source
739749
740750 ++ slag :: suffix
741751 ~/ %slag
742− |* {a/@ b/(list)}
752+ |* [a=@ b=(list)]
743753 |- ^+ b
744754 ?: =(0 a) b
745755 ?~ b ~
746756 $(b t.b, a (dec a))
747757
748758
749−Examples
750−--------
759+#### Examples
751760
752761 > (slag 2 (limo [1 2 3 4 ~]))
753762 [i=3 t=[i=4 t=~]]
@@ -764,22 +773,19 @@ Index
764773Accepts an atom `a` and a `++list` `b`, producing the element at the index
765774of `a`and failing if the list is null. Lists are 0-indexed.
766775
767−Accepts
768−-------
776+#### Accepts
769777
770778`b` is a list.
771779
772−Produces
773−--------
780+#### Produces
774781
775782Produces an element of `b`, or crashes if no element exists at that index.
776783
777−Source
778−------
784+#### Source
779785
780786 ++ snag :: index
781787 ~/ %snag
782− |* {a/@ b/(list)}
788+ |* [a=@ b=(list)]
783789 |-
784790 ?~ b
785791 ~|('snag-fail' !!)
@@ -787,8 +793,7 @@ Source
787793 $(b t.b, a (dec a))
788794
789795
790−Examples
791−--------
796+#### Examples
792797
793798 > (snag 2 "asdf")
794799 ~~d
@@ -803,25 +808,22 @@ Examples
803808Quicksort
804809
805810Quicksort: 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`,
811+produces a flag. `++sort` then produces a list of the elements of `a`,
807812sorted according to `b`.
808813
809−Accepts
810−-------
814+#### Accepts
811815
812816`b` is a gate that accepts two nouns and produces a boolean.
813817
814−Produces
815−--------
818+#### Produces
816819
817820A list
818821
819−Source
820−------
822+#### Source
821823
822824 ++ sort !. :: quicksort
823825 ~/ %sort
824− |* {a/(list) b/$-([* *] ?)}
826+ |* [a=(list) b=$-([* *] ?)]
825827 => .(a ^.(homo a))
826828 |- ^+ a
827829 ?~ a ~
@@ -831,91 +833,14 @@ Source
831833 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
832834
833835
834−Examples
835−--------
836+#### Examples
836837
837− > =a =|({p/@ q/@} |.((gth p q)))
838+ > =a =|([p/@ q/@] |.((gth p q)))
838839 > (sort (limo [0 1 2 3 ~]) a)
839840 ~[3 2 1 0]
840841
841842
842843
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−
919844***
920845### `++spin`
921846
@@ -927,8 +852,7 @@ a tuple -- the head is an element of `a` and the tail is the state `c`, and
927852should produce a tuple of the transformed element and the (potentially
928853modified) state `c`.
929854
930−Accepts
931−-------
855+#### Accepts
932856
933857`a` is a `++list`.
934858
@@ -936,49 +860,43 @@ Accepts
936860
937861`c` is a noun.
938862
939−Produces
940−--------
863+#### Produces
941864
942865A list.
943866
944−Source
945−------
867+#### Source
946868
947869 ++ spin
948− |* {a/(list) b/_|=({* *} [** +<+]) c/*}
949− :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
950− |-
870+ ~/ %spin
871+ |* [a=(list) b=* c=_|=(^ [** +<+])]
872+ => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
873+ =/ acc=(list _-:(c)) ~
874+ |- ^- (pair _acc _b)
951875 ?~ a
952− ~
953− =+ v=(b i.a c)
954− [i=-.v t=$(a t.a, c +.v)]
876+ [(flop acc) b]
877+ =^ res b (c i.a b)
878+ $(acc [res acc], a t.a)
955879
956880
957−Examples
958−--------
881+#### Examples
959882
960−A trivial example -- does nothing with the state:
961883
962− > %^ spin (limo ~[4 5 6])
963− |=({n/@ a/@} [n a])
884+ > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
885+ |=([n=@ a=@] [n a])
964886 0
965887 ~[4 5 6]
966888
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)])
889+ > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
890+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
971891 0
972892 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
973893
974−Create 10 random numbers less than `10`:
975−
976− > %^ spin (reap 10 0)
977− |=({n/@ rng/_og} (rads:rng 10))
894+ > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
895+ |=([n=@ rng=_og] (rads:rng 10))
978896 ~(. og eny)
979897 ~[5 5 9 4 1 7 9 9 9 6]
980898
981−*Notes*:
899+#### Discussion
982900
983901`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
984902with entropy (`eny`). The head of the product is the random number, the tail
@@ -991,57 +909,115 @@ is the continuation of the RNG.
991909
992910Gate to list, with state
993911
994−Accepts a `++list` `a` and a gate `b`. `c` is internal state, initially
912+Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
995913derived by *bunting* the tail of the sample of gate `b`, instead of
996914being 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
915+gate applied to each element of the original list. `b` is called with a tuple --
916+ the head is an element of `a` and the tail is the state `c`, and should
999917produce a tuple of the transformed element and the (potentially modified)
1000918state `c`.
1001919
1002−Accepts
1003−-------
920+#### Accepts
1004921
1005922`a` is a `++list`.
1006923
1007924`b` is a gate.
1008925
1009−Produces
1010−--------
926+#### Produces
1011927
1012928A list.
1013929
1014−Source
1015−------
930+#### Source
1016931
1017932 ++ spun
1018− |* {a/(list) b/_|=({* *} [** +<+])}
1019− =| c/_+<+.b
1020− |-
1021− ?~ a
1022− ~
1023− =+ v=(b i.a c)
1024− [i=-.v t=$(a t.a, c +.v)]
1025−
933+ ~/ %spun
934+ |* [a=(list) b=_|=(^ [** +<+])]
935+ p:(spin a +<+.b b)
1026936
1027−Examples
1028−--------
1029937
1030−Create a list of pairs, `p` as the index and `q` as the list element:
938+#### Examples
1031939
1032− > %+ spun (limo ~[4 5 6])
1033− |=({n/@ a/@} [`(pair)`[a n] +(a)])
940+ > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
941+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
1034942 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1035943
1036−Join two lists into a list of pairs, `p` from `l` and `q` from the sample:
1037−
1038− > =l (limo ~[7 8 9])
1039− > %+ spun (limo ~[4 5 6])
1040− |=({n/@ a/@} [`(pair)`[(snag a l) n] +(a)])
944+ > =l (limo ~[7 8 9])
945+ > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
946+ |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1041947 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1042948
1043949
1044950
951+***
952+### `++swag`
953+
954+Infix
955+
956+Similar to `substr` in Javascript: extracts a string infix, beginning at
957+inclusive index `a`, producing `b` number of characters.
958+
959+#### Accepts
960+
961+`c` is a list.
962+
963+#### Produces
964+
965+A list of the same type as `c`.
966+
967+#### Source
968+
969+ ++ swag
970+ |* [[a=@ a=@] c=(list)]
971+ (scag +<-> (slag +<-< c))
972+
973+
974+#### Examples
975+
976+ > (swag [2 5] "roly poly")
977+ "ly po"
978+
979+ > (swag [2 2] (limo [1 2 3 4 ~]))
980+ [i=3 t=[i=4 t=~]]
981+
982+
983+
984+***
985+### `++turn`
986+
987+Gate to list
988+
989+Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
990+to each element of the original list.
991+
992+#### Accepts
993+
994+`b` is a gate.
995+
996+#### Produces
997+
998+A list.
999+
1000+#### Source
1001+
1002+ ++ turn
1003+ ~/ %turn
1004+ |* [a=(list) b=gate]
1005+ |-
1006+ ?~ a ~
1007+ [i=(b i.a) t=$(a t.a)]
1008+
1009+
1010+#### Examples
1011+
1012+ > (turn (limo [104 111 111 110 ~]) @t)
1013+ <|h o o n|>
1014+
1015+ > =a |=(a=@ (add a 4))
1016+ > (turn (limo [1 2 3 4 ~]) a)
1017+ ~[5 6 7 8]
1018+
1019+
1020+
10451021***
10461022### `++weld`
10471023
@@ -1049,28 +1025,26 @@ Concatenate
10491025
10501026Concatenate two `++list`s `a` and `b`.
10511027
1052−Accepts
1053−-------
1028+#### Accepts
10541029
10551030`a` and `b` are lists.
10561031
1057−Source
1058−------
1032+#### Source
10591033
1060− ++ weld :: concatenate
1034+ ++ weld
10611035 ~/ %weld
1062− |* {a/(list) b/(list)}
1036+ |* [a=(list) b=(list)]
10631037 => .(a ^.(homo a), b ^.(homo b))
10641038 |- ^+ b
10651039 ?~ a b
10661040 [i.a $(a t.a)]
10671041
10681042
1069−Examples
1070−--------
1043+#### Examples
10711044
10721045 > (weld "urb" "it")
10731046 ~[~~u ~~r ~~b ~~i ~~t]
1047+
10741048 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
10751049 ~[1 2 3 4]
10761050
@@ -1084,23 +1058,20 @@ Perfect weld
10841058Concatenate two `++list`s `a` and `b` without losing their type information
10851059to homogenization.
10861060
1087−Accepts
1088−-------
1061+#### Accepts
10891062
10901063`a` is a list.
10911064
10921065`b` is a list.
10931066
1094−Produces
1095−--------
1067+#### Produces
10961068
10971069A list.
10981070
1099−Source
1100−------
1071+#### Source
11011072
1102− ++ welp :: perfect weld
1103− =| {* *}
1073+ ++ welp
1074+ =| [* *]
11041075 |%
11051076 +- $
11061077 ?~ +<-
@@ -1109,18 +1080,20 @@ Source
11091080 --
11101081
11111082
1112−Examples
1113−--------
1083+#### Examples
11141084
11151085 > (welp "foo" "bar")
11161086 "foobar"
1117− ~zod/arvo=/hoon/hoon> (welp ~[60 61 62] ~[%a %b %c])
1087+
1088+ > (welp ~[60 61 62] ~[%a %b %c])
11181089 [60 61 62 %a %b %c ~]
1119− ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1090+
1091+ > ? (welp ~[60 61 62] ~[%a %b %c])
1092+ {@ud @ud @ud $a $b $c $~}
11201093 [60 61 62 %a %b %c ~]
1121− [@ud @ud @ud %a %b %c %~]
1122− ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si/3)
1123− [[%sa 1] [%so 2] %si 3]
1094+
1095+ > (welp [sa+1 so+2 ~] si=3)
1096+ [[%sa 1] [%so 2] si=3]
11241097
11251098
11261099
@@ -1132,20 +1105,17 @@ Cons
11321105Turns a `++list` of lists into a single list by promoting the elements of
11331106each sublist into the higher.
11341107
1135−Accepts
1136−-------
1108+#### Accepts
11371109
11381110A list of lists.
11391111
1140−Produces
1141−--------
1112+#### Produces
11421113
11431114A list.
11441115
1145−Source
1146−------
1116+#### Source
11471117
1148− ++ zing :: promote
1118+ ++ zing
11491119 =| *
11501120 |%
11511121 +- $
@@ -1156,11 +1126,11 @@ Source
11561126
11571127
11581128
1159−Examples
1160−--------
1129+#### Examples
11611130
11621131 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
11631132 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1133+
11641134 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
11651135 ~[1 97 2 98 3 99 4 100]
11661136