@@ -4,28 +4,132 @@ navhome: /docs/
6# 2b: list logic
6# 2b: list logic
11+Produces the indices of all occurrences of `list` `nedl` in
12+`list` `hstk` as a `list` of atoms.
26+ ++ fand :: all indices
28+ |= [nedl=(list) hstk=(list)]
34+ ?: |(?=($~ n) ?=($~ h))
38+ ^$(i +(i), hstk +.hstk, fnd [i fnd])
40+ ^$(i +(i), hstk +.hstk)
45+ > (fand [3]~ ~[1 2 3])
48+ > (fand [4]~ ~[1 2 3])
51+ > (fand ['a']~ "cbabab")
54+ > (fand "ba" "cbabab")
64+Produces the index of the first occurrence of `list` `nedl` in
65+`list` `hstk` as the `unit` of an atom.
75+The `unit` of an atom.
79+ ++ find :: first index
81+ |= [nedl=(list) hstk=(list)]
86+ ?: |(?=($~ n) ?=($~ h))
92+ ^$(i +(i), hstk +.hstk)
97+ > (find [3]~ ~[1 2 3])
100+ > (find [4]~ ~[1 2 3])
103+ > (find ['c']~ "cbabab")
106+ > (find "ab" "cbabab")
109+ > (find "bab" "cbabab")
9### `++flop`
114### `++flop`
11−Produces the list `a` in reverse order.
116+Reverse
13−Accepts
118+Produces the `list` `a` in reverse order.
16−`a` is a list.
120+#### Accepts
18−Produces
122+`a` is a `list`.
26 ++ flop :: reverse
130 ++ flop :: reverse
28− |* a/(list)
132+ |* a=(list)
29 => .(a (homo a))
133 => .(a (homo a))
31 =+ b=`_a`~
135 =+ b=`_a`~
@@ -35,46 +139,75 @@ Source
38−Examples
142+#### Examples
41− > =a (limo [1 2 3 ~])
144+ > =a [1 2 3 ~]
42 > (flop a)
145 > (flop a)
156+Produces a `list` composed of each consecutive integer starting from `a` and
157+ending with `b`. `a` and `b` are themselves included.
171+ ++ gulf :: range inclusive
174+ ?:(=(a +(b)) ~ [a $(a +(a))])
181+ > `(list @t)`(gulf 99 106)
48### `++homo`
185### `++homo`
50Homogenize
187Homogenize
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
53list `a`. Used when you want to make all the types of the elements of a list the same.
190list `a`. Used when you want to make all the types of the elements of a list the same.
55−Accepts
192+#### Accepts
58−`a` is a list.
194+`a` is a `list`.
60−Produces
196+#### Produces
68 ++ homo :: homogenize
202 ++ homo :: homogenize
69− |* a/(list)
203+ |* a=(list)
71 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
205 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
76−Examples
210+#### Examples
80 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
213 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
@@ -93,24 +226,21 @@ Examples
94List length
227List length
96−Produces the length of any `++list` `a` as an atom.
229+Produces the length of any `list` `a` as an atom.
98−Accepts
231+#### Accepts
101−`a` is a list.
233+`a` is a `list`.
103−Produces
235+#### Produces
108−Source
239+#### Source
111 ++ lent :: length
241 ++ lent :: length
113− |= a/(list)
243+ |= a=(list)
@@ -118,120 +248,13 @@ Source
118 $(a t.a, b +(b))
248 $(a t.a, b +(b))
121−Examples
251+#### Examples
124− > (lent (limo [1 2 3 4 ~]))
253+ > (lent [1 2 3 4 ~]))
126− > (lent (limo [1 'a' 2 'b' (some 10) ~]))
136−Produces the index of the first occurrence of `++list` `nedl` in
137−`++list` `hstk` as the `++unit` of an atom.
149−The `++unit` of an atom.
154− ++ find :: first index
156− |= {nedl/(list) hstk/(list)}
161− ?: |(?=($~ n) ?=($~ h))
167− ^$(i +(i), hstk +.hstk)
173− > (find [3]~ ~[1 2 3])
175− > (find [4]~ ~[1 2 3])
177− > (find ['a']~ "cbabab")
179− > (find "ab" "cbabab")
187−All indices in list
256+ > (lent [1 'a' 2 'b' (some 10) ~])
189−Produces the indices of all occurrences of `++list` `nedl` in
190−`++list` `hstk` as a `++list` of atoms.
207− ++ fand :: all indices
209− |= {nedl/(list) hstk/(list)}
215− ?: |(?=($~ n) ?=($~ h))
219− ^$(i +(i), hstk +.hstk, fnd [i fnd])
221− ^$(i +(i), hstk +.hstk)
227− > (fand [3]~ ~[1 2 3])
229− > (fand [4]~ ~[1 2 3])
231− > (fand ['a']~ "cbabab")
233− > (fand "ab" "cbabab")
@@ -240,40 +263,37 @@ Examples
241Logical "and" on list
264Logical "and" on list
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`.
245−Accepts
268+#### Accepts
248`a` is a list.
270`a` is a list.
250`b` is a gate.
272`b` is a gate.
252−Produces
274+#### Produces
255A boolean.
276A boolean.
257−Source
278+#### Source
261 ~/ %levy :: all of
281 ~/ %levy :: all of
262− |* {a/(list) b/$-(* ?)}
282+ |* [a=(list) b=$-(* ?)]
265 ?. (b i.a) |
285 ?. (b i.a) |
269−Examples
289+#### Examples
272− > =a |=(a/@ (lte a 1))
291+ > =a |=(a=@ (lte a 1))
273− > (levy (limo [0 1 2 1 ~]) a)
292+ > (levy `(list @)`[0 1 2 1 ~] a)
275− > =a |=(a/@ (lte a 3))
295+ > =a |=(a=@ (lte a 3))
276− > (levy (limo [0 1 2 1 ~]) a)
296+ > (levy `(list @)`[0 1 2 1 ~] a)
@@ -283,34 +303,32 @@ Examples
284Logical "or" on list
304Logical "or" on list
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`.
288−Accepts
309+#### Accepts
291`a` is a list.
311`a` is a list.
293`b` is a gate.
313`b` is a gate.
295−Source
315+#### Source
298 ++ lien :: some of
317 ++ lien :: some of
300− |* {a/(list) b/$-(* ?)}
319+ |* [a=(list) b=$-(* ?)]
303 ?: (b i.a) &
322 ?: (b i.a) &
306−Examples
325+#### Examples
309 > =a |=(a=@ (gte a 1))
327 > =a |=(a=@ (gte a 1))
310− > (lien (limo [0 1 2 1 ~]) a)
328+ > (lien `(list @)`[0 1 2 1 ~] a)
312 > =a |=(a=@ (gte a 3))
330 > =a |=(a=@ (gte a 3))
313− > (lien (limo [0 1 2 1 ~]) a)
331+ > (lien `(list @)`[0 1 2 1 ~]) a)
@@ -320,20 +338,17 @@ Examples
321List Constructor
339List Constructor
323−Turns a null-terminated tuple into a [`++list`]().
341+Turns a null-terminated tuple into a `list`.
325−Accepts
343+#### Accepts
328`a` is a null-terminated tuple.
345`a` is a null-terminated tuple.
330−Produces
347+#### Produces
333A `++list`.
349A `++list`.
335−Source
351+#### Source
338 ++ limo :: listify
353 ++ limo :: listify
@@ -342,8 +357,7 @@ Source
345−Examples
360+#### Examples
348 > (limo [1 2 3 ~])
362 > (limo [1 2 3 ~])
349 [i=1 t=[i=2 t=[i=3 t=~]]]
363 [i=1 t=[i=2 t=[i=3 t=~]]]
@@ -355,28 +369,25 @@ Examples
356Maybe transform
370Maybe transform
358−Passes each member of `++list` `a` to gate `b`, which must produce a
372+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
373+`unit`. Produces a new list with all the results that do not produce
362−Accepts
376+#### Accepts
365`a` is a list.
378`a` is a list.
367`b` is a gate that produces a unit.
380`b` is a gate that produces a unit.
369−Produces
382+#### Produces
374−Source
386+#### Source
377 ++ murn :: maybe transform
388 ++ murn :: maybe transform
379− |* {a/(list) b/$-(* (unit))}
390+ |* [a=(list) b=$-(* (unit))]
382 =+ c=(b i.a)
393 =+ c=(b i.a)
@@ -384,11 +395,10 @@ Source
385 [i=u.c t=$(a t.a)]
396 [i=u.c t=$(a t.a)]
387−Examples
398+#### Examples
390 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
400 > =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)
392 [i=12 t=[i=13 t=~]]
402 [i=12 t=[i=13 t=~]]
@@ -398,33 +408,31 @@ Examples
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`
403−Accepts
414+#### Accepts
406`c` is a list.
416`c` is a list.
408−Produces
418+#### Produces
411A `++list`.
420A `++list`.
413−Source
422+#### Source
416 ++ oust :: remove
424 ++ oust :: remove
418− |* {{a/@ b/@} c/(list)}
426+ |* [[a=@ b=@] c=(list)]
419 (weld (scag a c) (slag (add a b) c))
427 (weld (scag a c) (slag (add a b) c))
421−Examples
429+#### Examples
424 > (oust [4 5] "good day, urbit!")
431 > (oust [4 5] "good day, urbit!")
425 "good urbit!"
432 "good urbit!"
426− > (oust [2 2] (limo [1 2 3 4 ~]))
434+ > (oust [2 2] `(list @)`[1 2 3 4 ~])
427− [i=1 t=[i=2 t=~]]
435+ ~[1 2]
@@ -433,35 +441,35 @@ Examples
436−Replicate: produces a `++list` containing `a` copies of `b`.
444+Replicate: produces a `list` containing `a` copies of `b`.
438−Accepts
448+`a` is an atom.
441`b` is a noun.
450`b` is a noun.
443−Produces
452+#### Produces
448−Source
456+#### Source
451 ++ reap :: replicate
458 ++ reap :: replicate
453− |* {a/@ b/*}
460+ |* [a=@ b=*]
454 |- ^- (list _b)
461 |- ^- (list _b)
456 [b $(a (dec a))]
463 [b $(a (dec a))]
458−Examples
465+#### Examples
461 > (reap 20 %a)
467 > (reap 20 %a)
462 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
468 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
463 > (reap 5 ~s1)
470 > (reap 5 ~s1)
464 ~[~s1 ~s1 ~s1 ~s1 ~s1]
471 ~[~s1 ~s1 ~s1 ~s1 ~s1]
465 > `@dr`(roll (reap 5 ~s1) add)
473 > `@dr`(roll (reap 5 ~s1) add)
@@ -472,41 +480,44 @@ Examples
473Right fold
481Right fold
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
476a binary gate `b` with an element from `a` and an accumulator, producing
484a binary gate `b` with an element from `a` and an accumulator, producing
477the final value of the accumulator.
485the final value of the accumulator.
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.)
479−Accepts
490+#### Accepts
482`b` is a binary gate.
494`b` is a binary gate.
484−Produces
496+#### Produces
487The accumulator, which is a noun.
498The accumulator, which is a noun.
489−Source
500+#### Source
492 ++ reel :: right fold
502 ++ reel :: right fold
494− |* {a/(list) b/_|=({* *} +<+)}
504+ |* [a=(list) b=_|=([* *] +<+)]
495 |- ^+ +<+.b
505 |- ^+ +<+.b
498 (b i.a $(a t.a))
508 (b i.a $(a t.a))
501−Examples
511+#### Examples
504 > =sum =|([p=@ q=@] |.((add p q)))
513 > =sum =|([p=@ q=@] |.((add p q)))
505 > (reel (limo [1 2 3 4 5 ~]) sum)
514 > (reel (limo [1 2 3 4 5 ~]) sum)
507 > =a =|([p=@ q=@] |.((sub p q)))
517 > =a =|([p=@ q=@] |.((sub p q)))
508 > (reel (limo [6 3 1 ~]) a)
518 > (reel (limo [6 3 1 ~]) a)
510 > (reel (limo [3 6 1 ~]) a)
521 > (reel (limo [3 6 1 ~]) a)
511 ! subtract-underflow
522 ! subtract-underflow
@@ -519,21 +530,23 @@ Examples
521Left fold: moves left to right across a list `a`, recursively slamming a
532Left 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,
523producing the final value of the accumulator.
534producing the final value of the accumulator.
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.)
525−Accepts
539+#### Accepts
528−`b` is a binary [gate]().
543+`b` is a binary gate.
530−Produces
545+#### Produces
533−The accumulator, which is a [noun]().
547+The accumulator, which is a noun.
535−Source
549+#### Source
538 ++ roll :: left fold
551 ++ roll :: left fold
@@ -543,8 +556,7 @@ Source
544 $(a t.a, b b(+<+ (b i.a +<+.b)))
557 $(a t.a, b b(+<+ (b i.a +<+.b)))
546−Examples
559+#### Examples
549 > =sum =|([p=@ q=@] |.((add p q)))
561 > =sum =|([p=@ q=@] |.((add p q)))
550 > (roll (limo [1 2 3 4 5 ~]) sum)
562 > (roll (limo [1 2 3 4 5 ~]) sum)
@@ -563,21 +575,20 @@ Examples
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
567the front of the list.
579the front of the list.
569−Accepts
581+#### Accepts
572`b` is a list.
585`b` is a list.
574−Produces
587+#### Produces
577A list of the same type as `b`.
589A list of the same type as `b`.
579−Source
591+#### Source
582 ++ scag :: prefix
593 ++ scag :: prefix
@@ -586,13 +597,13 @@ Source
586 ?: |(?=(~ b) =(0 a)) ~
597 ?: |(?=(~ b) =(0 a)) ~
587 [i.b $(b t.b, a (dec a))]
598 [i.b $(b t.b, a (dec a))]
589−Examples
600+#### Examples
592− > (scag 2 (limo [0 1 2 3 ~]))
602+ > (scag 2 `(list @)`[1 2 3 4 ~])
593− [i=0 t=[i=1 t=~]]
603+ [i=0 t=~[1]]
594− > (scag 10 (limo [1 2 3 4 ~]))
605+ > (scag 10 `(list @)`[1 2 3 4 ~])
595− [i=1 t=[i=2 t=[i=3 t=[i=4 t=~]]]]
606+ [i=1 t=~[2 3 4]]
@@ -601,25 +612,27 @@ Examples
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
605true when slammed to gate `b` and those who produce `%.n`.
616true when slammed to gate `b` and those who produce `%.n`.
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`.)
607−Accepts
621+#### Accepts
610−`b` is a gate that accepts one argument and produces a loobean.
625+`b` is a gate that accepts one argument and produces a flag.
612−Produces
627+#### Produces
615A cell of two lists.
629A cell of two lists.
617−Source
631+#### Source
620 ++ skid :: separate
633 ++ skid :: separate
622− |* {a/(list) b/$-(* ?)}
635+ |* [a=(list) b=$-(* ?)]
623 |- ^+ [p=a q=a]
636 |- ^+ [p=a q=a]
624 ?~ a [~ ~]
637 ?~ a [~ ~]
625 =+ c=$(a t.a)
638 =+ c=$(a t.a)
@@ -627,12 +640,11 @@ Source
630−Examples
643+#### Examples
633− > =a |=(a/@ (gth a 1))
645+ > =a |=(a=@ (gth a 1))
634− > (skid (limo [0 1 2 3 ~]) a)
646+ > (skid `(list @)`[0 1 2 3 ~]) a)
635− [p=[i=2 t=[i=3 t=~]] q=[i=0 t=[i=1 t=~]]]
647+ (skid `(list @)`[0 1 2 3 ~]) a)
@@ -643,36 +655,34 @@ Suffix
644Cycles through the members of a list `a`, passing them to a gate `b` and
656Cycles through the members of a list `a`, passing them to a gate `b` and
645producing a list of all of the members that produce `%.y`. Inverse of
657producing a list of all of the members that produce `%.y`. Inverse of
648−Accepts
660+#### Accepts
651`b` is a gate that accepts one argument and produces a boolean.
664`b` is a gate that accepts one argument and produces a boolean.
653−Produces
666+#### Produces
658−Source
670+#### Source
661 ++ skim :: only
672 ++ skim :: only
663− |* {a/(list) b/$-(* ?)}
674+ |* [a=(list) b=$-(* ?)]
667 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
678 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
670−Examples
681+#### Examples
673− > =a |=(a/@ (gth a 1))
683+ > =a |=(a=@ (gth a 1))
674− > (skim (limo [0 1 2 3 ~]) a)
684+ > (skim `(list @)`[0 1 2 3 ~] a)
675− [i=2 t=[i=3 t=~]]
685+ [i=2 t=~[3]]
@@ -681,37 +691,35 @@ Examples
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`.
685Produces a list of all of the members that produce `%.n`. Inverse of
695Produces a list of all of the members that produce `%.n`. Inverse of
688−Accepts
700+`a` is a list.
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.
693−Produces
704+#### Produces
696A list of the same type as `a`.
706A list of the same type as `a`.
698−Source
708+#### Source
701 ++ skip :: except
710 ++ skip :: except
703− |* {a/(list) b/$-(* ?)}
712+ |* [a=(list) b=$-(* ?)]
707 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
716 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
710−Examples
719+#### Examples
713− > =a |=(a/@ (gth a 1))
721+ > =a |=(a=@ (gth a 1))
714− > (skip (limo [0 1 2 3 ~]) a)
722+ > (skip `(l)`[0 1 2 3 ~]) a)
715 [i=0 t=[i=1 t=~]]
723 [i=0 t=[i=1 t=~]]
@@ -724,30 +732,26 @@ Suffix
724Accepts an atom `a` and list `b`, producing the remaining elements from
732Accepts an atom `a` and list `b`, producing the remaining elements from
725`b` starting at `a`.
733`b` starting at `a`.
727−Accepts
735+#### Accepts
730`b` is a list.
737`b` is a list.
732−Produces
739+#### Produces
735A list of the same type as `b`.
741A list of the same type as `b`.
737−Source
743+#### Source
740 ++ slag :: suffix
745 ++ slag :: suffix
742− |* {a/@ b/(list)}
747+ |* [a=@ b=(list)]
744 ?: =(0 a) b
749 ?: =(0 a) b
746 $(b t.b, a (dec a))
751 $(b t.b, a (dec a))
749−Examples
754+#### Examples
752 > (slag 2 (limo [1 2 3 4 ~]))
756 > (slag 2 (limo [1 2 3 4 ~]))
753 [i=3 t=[i=4 t=~]]
757 [i=3 t=[i=4 t=~]]
@@ -764,22 +768,19 @@ Index
764Accepts an atom `a` and a `++list` `b`, producing the element at the index
768Accepts an atom `a` and a `++list` `b`, producing the element at the index
765of `a`and failing if the list is null. Lists are 0-indexed.
769of `a`and failing if the list is null. Lists are 0-indexed.
767−Accepts
771+#### Accepts
770`b` is a list.
773`b` is a list.
772−Produces
775+#### Produces
775Produces an element of `b`, or crashes if no element exists at that index.
777Produces an element of `b`, or crashes if no element exists at that index.
777−Source
779+#### Source
780 ++ snag :: index
781 ++ snag :: index
782− |* {a/@ b/(list)}
783+ |* [a=@ b=(list)]
785 ~|('snag-fail' !!)
786 ~|('snag-fail' !!)
@@ -787,8 +788,7 @@ Source
787 $(b t.b, a (dec a))
788 $(b t.b, a (dec a))
790−Examples
791+#### Examples
793 > (snag 2 "asdf")
793 > (snag 2 "asdf")
@@ -803,25 +803,22 @@ Examples
805Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
805Quicksort: 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`,
807sorted according to `b`.
807sorted according to `b`.
809−Accepts
809+#### Accepts
812`b` is a gate that accepts two nouns and produces a boolean.
811`b` is a gate that accepts two nouns and produces a boolean.
814−Produces
813+#### Produces
819−Source
817+#### Source
822 ++ sort !. :: quicksort
819 ++ sort !. :: quicksort
824− |* {a/(list) b/$-([* *] ?)}
821+ |* [a=(list) b=$-([* *] ?)]
825 => .(a ^.(homo a))
822 => .(a ^.(homo a))
@@ -831,91 +828,14 @@ Source
831 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
828 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
834−Examples
831+#### Examples
837− > =a =|({p/@ q/@} |.((gth p q)))
833+ > =a =|([p/@ q/@] |.((gth p q)))
838 > (sort (limo [0 1 2 3 ~]) a)
834 > (sort (limo [0 1 2 3 ~]) a)
839 ~[3 2 1 0]
835 ~[3 2 1 0]
848−Similar to `substr` in Javascript: extracts a string infix, beginning at
849−inclusive index `a`, producing `b` number of characters.
859−A list of the same type as `c`.
865− |* {{a/@ b/@} c/(list)}
866− (scag +<-> (slag +<-< c))
872− > (swag [2 5] "roly poly")
874− > (swag [2 2] (limo [1 2 3 4 ~]))
884−Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
885−to each element of the original list.
900− ++ turn :: transform
902− |* {a/(list) b/gate}
905− [i=(b i.a) t=$(a t.a)]
911− > (turn (limo [104 111 111 110 ~]) @t)
913− > =a |=(a/@ (add a 4))
914− > (turn (limo [1 2 3 4 ~]) a)
920### `++spin`
840### `++spin`
@@ -927,8 +847,7 @@ a tuple -- the head is an element of `a` and the tail is the state `c`, and
927should produce a tuple of the transformed element and the (potentially
847should produce a tuple of the transformed element and the (potentially
928modified) state `c`.
848modified) state `c`.
930−Accepts
850+#### Accepts
933`a` is a `++list`.
852`a` is a `++list`.
@@ -936,16 +855,14 @@ Accepts
937`c` is a noun.
856`c` is a noun.
939−Produces
858+#### Produces
944−Source
862+#### Source
948− |* {a/(list) b/_|=({* *} [** +<+]) c/*}
865+ |* [a=(list) b=_|=([* *] [** +<+]) c/*]
949 :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
866 :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
@@ -954,31 +871,25 @@ Source
954 [i=-.v t=$(a t.a, c +.v)]
871 [i=-.v t=$(a t.a, c +.v)]
957−Examples
874+#### Examples
960−A trivial example -- does nothing with the state:
962− > %^ spin (limo ~[4 5 6])
877+ > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
963− |=({n/@ a/@} [n a])
878+ |=([n=@ a=@] [n a])
967−Create a list of pairs, `p` as the index and `q` as the list element:
969− > %^ spin (limo ~[4 5 6])
882+ > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
970− |=({n/@ a/@} [`(pair)`[a n] +(a)])
883+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
972 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
885 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
974−Create 10 random numbers less than `10`:
976− > %^ spin (reap 10 0)
887+ > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
977− |=({n/@ rng/_og} (rads:rng 10))
888+ |=([n=@ rng=_og] (rads:rng 10))
978 ~(. og eny)
889 ~(. og eny)
979 ~[5 5 9 4 1 7 9 9 9 6]
890 ~[5 5 9 4 1 7 9 9 9 6]
981−*Notes*:
892+#### Discussion
983`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
894`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
984with entropy (`eny`). The head of the product is the random number, the tail
895with entropy (`eny`). The head of the product is the random number, the tail
@@ -991,31 +902,27 @@ is the continuation of the RNG.
992Gate to list, with state
903Gate to list, with state
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
995derived by *bunting* the tail of the sample of gate `b`, instead of
906derived by *bunting* the tail of the sample of gate `b`, instead of
996being passed in explicitly as in `++spin`. Produces a list with the
907being 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
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
998−-- the head is an element of `a` and the tail is the state `c`, and should
999produce a tuple of the transformed element and the (potentially modified)
909produce a tuple of the transformed element and the (potentially modified)
1000state `c`.
910state `c`.
1002−Accepts
912+#### Accepts
1005`a` is a `++list`.
914`a` is a `++list`.
1007`b` is a gate.
916`b` is a gate.
1009−Produces
918+#### Produces
1014−Source
922+#### Source
1018− |* {a/(list) b/_|=({* *} [** +<+])}
925+ |* [a=(list) b=_|=([* *] [** +<+])]
1019 =| c/_+<+.b
926 =| c/_+<+.b
@@ -1024,24 +931,88 @@ Source
1024 [i=-.v t=$(a t.a, c +.v)]
931 [i=-.v t=$(a t.a, c +.v)]
1027−Examples
934+#### Examples
1030−Create a list of pairs, `p` as the index and `q` as the list element:
1032− > %+ spun (limo ~[4 5 6])
936+ > %+ spun (limo ~[4 5 6]) ::`p` as the index and `q` as the list element
1033− |=({n/@ a/@} [`(pair)`[a n] +(a)])
937+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
1034 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
938 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1036−Join two lists into a list of pairs, `p` from `l` and `q` from the sample:
940+ > =l (limo ~[7 8 9]) ::joins two lists into a list of pairs
1038− > =l (limo ~[7 8 9])
1039 > %+ spun (limo ~[4 5 6])
941 > %+ spun (limo ~[4 5 6])
1040− |=({n/@ a/@} [`(pair)`[(snag a l) n] +(a)])
942+ |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1041 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
943 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
952+Similar to `substr` in Javascript: extracts a string infix, beginning at
953+inclusive index `a`, producing `b` number of characters.
961+A list of the same type as `c`.
966+ |* [[a=@ a=@] c=(list)]
967+ (scag +<-> (slag +<-< c))
972+ > (swag [2 5] "roly poly")
974+ > (swag [2 2] (limo [1 2 3 4 ~]))
984+Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
985+to each element of the original list.
999+ |* [a=(list) b=gate]
1002+ [i=(b i.a) t=$(a t.a)]
1007+ > (turn (limo [104 111 111 110 ~]) @t)
1010+ > =a |=(a=@ (add a 4))
1011+ > (turn (limo [1 2 3 4 ~]) a)
1046### `++weld`
1017### `++weld`
@@ -1049,25 +1020,22 @@ Concatenate
1050Concatenate two `++list`s `a` and `b`.
1021Concatenate two `++list`s `a` and `b`.
1052−Accepts
1023+#### Accepts
1055`a` and `b` are lists.
1025`a` and `b` are lists.
1057−Source
1027+#### Source
1060− ++ weld :: concatenate
1029+ ++ weld
1061 ~/ %weld
1030 ~/ %weld
1062− |* {a/(list) b/(list)}
1031+ |* [a=(list) b=(list)]
1063 => .(a ^.(homo a), b ^.(homo b))
1032 => .(a ^.(homo a), b ^.(homo b))
1066 [i.a $(a t.a)]
1035 [i.a $(a t.a)]
1069−Examples
1038+#### Examples
1072 > (weld "urb" "it")
1040 > (weld "urb" "it")
1073 ~[~~u ~~r ~~b ~~i ~~t]
1041 ~[~~u ~~r ~~b ~~i ~~t]
@@ -1084,23 +1052,20 @@ Perfect weld
1084Concatenate two `++list`s `a` and `b` without losing their type information
1052Concatenate two `++list`s `a` and `b` without losing their type information
1085to homogenization.
1053to homogenization.
1087−Accepts
1055+#### Accepts
1090`a` is a list.
1057`a` is a list.
1092`b` is a list.
1059`b` is a list.
1094−Produces
1061+#### Produces
1099−Source
1065+#### Source
1102− ++ welp :: perfect weld
1067+ ++ welp
1103− =| {* *}
1068+ =| [* *]
@@ -1109,8 +1074,7 @@ Source
1112−Examples
1077+#### Examples
1115 > (welp "foo" "bar")
1079 > (welp "foo" "bar")
1116 "foobar"
1080 "foobar"
@@ -1119,7 +1083,7 @@ Examples
1119 ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1083 ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1120 [60 61 62 %a %b %c ~]
1084 [60 61 62 %a %b %c ~]
1121 [@ud @ud @ud %a %b %c %~]
1085 [@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)
1123 [[%sa 1] [%so 2] %si 3]
1087 [[%sa 1] [%so 2] %si 3]
@@ -1132,20 +1096,17 @@ Cons
1132Turns a `++list` of lists into a single list by promoting the elements of
1096Turns a `++list` of lists into a single list by promoting the elements of
1133each sublist into the higher.
1097each sublist into the higher.
1135−Accepts
1099+#### Accepts
1138A list of lists.
1101A list of lists.
1140−Produces
1103+#### Produces
1145−Source
1107+#### Source
1148− ++ zing :: promote
1109+ ++ zing
@@ -1156,11 +1117,11 @@ Source
1159−Examples
1120+#### Examples
1162 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1122 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1163 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1123 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1164 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1125 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1165 ~[1 97 2 98 3 99 4 100]
1126 ~[1 97 2 98 3 99 4 100]