@@ -4,28 +4,132 @@ navhome: /docs/
6# 2b: list logic
6# 2b: list logic
11+Produces the indices of all occurrences of `nedl` in `hstk` as a `list` of
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 `nedl` in `hstk` as the `unit`
75+The `unit` of an atom.
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`.
21−A list.
124+#### Produces
26− ++ flop :: reverse
130+ ++ flop
28− |* a/(list)
132+ |* a=(list)
29 => .(a (homo a))
133 => .(a (homo a))
31 =+ b=`_a`~
135 =+ b=`_a`~
@@ -35,54 +139,87 @@ 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.
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
53−list `a`. Used when you want to make all the types of the elements of a list the same.
190+list `a`. Used when you want to make all the types of the elements of a list the
55−Accepts
193+#### Accepts
58−`a` is a list.
195+`a` is a `list`.
60−Produces
197+#### Produces
68− ++ homo :: homogenize
203+ ++ homo
69− |* a/(list)
204+ |* a=(list)
71 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
206 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
76−Examples
211+#### Examples
80 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
214 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
81 > (homo lyst)
216 > (homo lyst)
82 ~[1 97 2 98 [~ u=10]]
217 ~[1 97 2 98 [~ u=10]]
83 > =a (limo [1 2 3 ~])
219 > =a (limo [1 2 3 ~])
85 [i=1 t=[i=2 t=[i=3 t=~]]]
221 [i=1 t=[i=2 t=[i=3 t=~]]]
86 > (homo a)
223 > (homo a)
@@ -93,24 +230,21 @@ Examples
94List length
231List length
96−Produces the length of any `++list` `a` as an atom.
233+Produces the length of any `list` `a` as an atom.
98−Accepts
235+#### Accepts
101−`a` is a list.
237+`a` is a `list`.
103−Produces
239+#### Produces
108−Source
243+#### Source
111− ++ lent :: length
245+ ++ lent
113− |= a/(list)
247+ |= a=(list)
@@ -118,120 +252,13 @@ Source
118 $(a t.a, b +(b))
252 $(a t.a, b +(b))
121−Examples
255+#### Examples
124− > (lent (limo [1 2 3 4 ~]))
257+ > (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")
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])
260+ > (lent [1 'a' 2 'b' (some 10) ~])
229− > (fand [4]~ ~[1 2 3])
231− > (fand ['a']~ "cbabab")
233− > (fand "ab" "cbabab")
@@ -240,40 +267,37 @@ Examples
241Logical "and" on list
268Logical "and" on list
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`.
245−Accepts
272+#### Accepts
248`a` is a list.
274`a` is a list.
250`b` is a gate.
276`b` is a gate.
252−Produces
278+#### Produces
255A boolean.
280A boolean.
257−Source
282+#### Source
261 ~/ %levy :: all of
285 ~/ %levy :: all of
262− |* {a/(list) b/$-(* ?)}
286+ |* [a=(list) b=$-(* ?)]
265 ?. (b i.a) |
289 ?. (b i.a) |
269−Examples
293+#### Examples
272− > =a |=(a/@ (lte a 1))
295+ > =a |=(a=@ (lte a 1))
273− > (levy (limo [0 1 2 1 ~]) a)
296+ > (levy `(list @)`[0 1 2 1 ~] a)
275− > =a |=(a/@ (lte a 3))
299+ > =a |=(a=@ (lte a 3))
276− > (levy (limo [0 1 2 1 ~]) a)
300+ > (levy `(list @)`[0 1 2 1 ~] a)
@@ -283,34 +307,33 @@ Examples
284Logical "or" on list
308Logical "or" on list
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`.
288−Accepts
313+#### Accepts
291`a` is a list.
315`a` is a list.
293`b` is a gate.
317`b` is a gate.
295−Source
319+#### Source
298− ++ lien :: some of
321+ ++ lien
300− |* {a/(list) b/$-(* ?)}
323+ |* [a=(list) b=$-(* ?)]
303 ?: (b i.a) &
326 ?: (b i.a) &
306−Examples
329+#### Examples
309 > =a |=(a=@ (gte a 1))
331 > =a |=(a=@ (gte a 1))
310− > (lien (limo [0 1 2 1 ~]) a)
332+ > (lien `(list @)`[0 1 2 1 ~] a)
312 > =a |=(a=@ (gte a 3))
335 > =a |=(a=@ (gte a 3))
313− > (lien (limo [0 1 2 1 ~]) a)
336+ > (lien `(list @)`[0 1 2 1 ~]) a)
@@ -320,20 +343,17 @@ Examples
321List Constructor
344List Constructor
323−Turns a null-terminated tuple into a [`++list`]().
346+Turns a null-terminated tuple into a `list`.
325−Accepts
348+#### Accepts
328`a` is a null-terminated tuple.
350`a` is a null-terminated tuple.
330−Produces
352+#### Produces
333A `++list`.
354A `++list`.
335−Source
356+#### Source
338 ++ limo :: listify
358 ++ limo :: listify
@@ -342,8 +362,7 @@ Source
345−Examples
365+#### Examples
348 > (limo [1 2 3 ~])
367 > (limo [1 2 3 ~])
349 [i=1 t=[i=2 t=[i=3 t=~]]]
368 [i=1 t=[i=2 t=[i=3 t=~]]]
@@ -355,28 +374,25 @@ Examples
356Maybe transform
375Maybe transform
358−Passes each member of `++list` `a` to gate `b`, which must produce a
377+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
378+`unit`. Produces a new list with all the results that do not produce
362−Accepts
381+#### Accepts
365`a` is a list.
383`a` is a list.
367`b` is a gate that produces a unit.
385`b` is a gate that produces a unit.
369−Produces
387+#### Produces
374−Source
391+#### Source
377 ++ murn :: maybe transform
393 ++ murn :: maybe transform
379− |* {a/(list) b/$-(* (unit))}
395+ |* [a=(list) b=$-(* (unit))]
382 =+ c=(b i.a)
398 =+ c=(b i.a)
@@ -384,11 +400,10 @@ Source
385 [i=u.c t=$(a t.a)]
401 [i=u.c t=$(a t.a)]
387−Examples
403+#### Examples
390 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
405 > =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)
392 [i=12 t=[i=13 t=~]]
407 [i=12 t=[i=13 t=~]]
@@ -398,33 +413,31 @@ Examples
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`
403−Accepts
419+#### Accepts
406`c` is a list.
421`c` is a list.
408−Produces
423+#### Produces
411A `++list`.
425A `++list`.
413−Source
427+#### Source
416 ++ oust :: remove
429 ++ oust :: remove
418− |* {{a/@ b/@} c/(list)}
431+ |* [[a=@ b=@] c=(list)]
419 (weld (scag a c) (slag (add a b) c))
432 (weld (scag a c) (slag (add a b) c))
421−Examples
434+#### Examples
424 > (oust [4 5] "good day, urbit!")
436 > (oust [4 5] "good day, urbit!")
425 "good urbit!"
437 "good urbit!"
426− > (oust [2 2] (limo [1 2 3 4 ~]))
439+ > (oust [2 2] `(list @)`[1 2 3 4 ~])
427− [i=1 t=[i=2 t=~]]
440+ ~[1 2]
@@ -433,35 +446,35 @@ Examples
436−Replicate: produces a `++list` containing `a` copies of `b`.
449+Replicate: produces a `list` containing `a` copies of `b`.
438−Accepts
453+`a` is an atom.
441`b` is a noun.
455`b` is a noun.
443−Produces
457+#### Produces
448−Source
461+#### Source
451 ++ reap :: replicate
463 ++ reap :: replicate
453− |* {a/@ b/*}
465+ |* [a=@ b=*]
454 |- ^- (list _b)
466 |- ^- (list _b)
456 [b $(a (dec a))]
468 [b $(a (dec a))]
458−Examples
470+#### Examples
461 > (reap 20 %a)
472 > (reap 20 %a)
462 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
473 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
463 > (reap 5 ~s1)
475 > (reap 5 ~s1)
464 ~[~s1 ~s1 ~s1 ~s1 ~s1]
476 ~[~s1 ~s1 ~s1 ~s1 ~s1]
465 > `@dr`(roll (reap 5 ~s1) add)
478 > `@dr`(roll (reap 5 ~s1) add)
@@ -472,41 +485,44 @@ Examples
473Right fold
486Right fold
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
476a binary gate `b` with an element from `a` and an accumulator, producing
489a binary gate `b` with an element from `a` and an accumulator, producing
477the final value of the accumulator.
490the final value of the accumulator.
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.)
479−Accepts
495+#### Accepts
482`b` is a binary gate.
499`b` is a binary gate.
484−Produces
501+#### Produces
487The accumulator, which is a noun.
503The accumulator, which is a noun.
489−Source
505+#### Source
492 ++ reel :: right fold
507 ++ reel :: right fold
494− |* {a/(list) b/_|=({* *} +<+)}
509+ |* [a=(list) b=_|=([* *] +<+)]
495 |- ^+ +<+.b
510 |- ^+ +<+.b
498 (b i.a $(a t.a))
513 (b i.a $(a t.a))
501−Examples
516+#### Examples
504 > =sum =|([p=@ q=@] |.((add p q)))
518 > =sum =|([p=@ q=@] |.((add p q)))
505 > (reel (limo [1 2 3 4 5 ~]) sum)
519 > (reel (limo [1 2 3 4 5 ~]) sum)
507 > =a =|([p=@ q=@] |.((sub p q)))
522 > =a =|([p=@ q=@] |.((sub p q)))
508 > (reel (limo [6 3 1 ~]) a)
523 > (reel (limo [6 3 1 ~]) a)
510 > (reel (limo [3 6 1 ~]) a)
526 > (reel (limo [3 6 1 ~]) a)
511 ! subtract-underflow
527 ! subtract-underflow
@@ -519,21 +535,23 @@ Examples
521Left fold: moves left to right across a list `a`, recursively slamming a
537Left 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,
523producing the final value of the accumulator.
539producing the final value of the accumulator.
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.)
525−Accepts
544+#### Accepts
528−`b` is a binary [gate]().
546+`a` is a list.
530−Produces
548+`b` is a binary gate.
533−The accumulator, which is a [noun]().
550+#### Produces
552+The accumulator, which is a noun.
535−Source
554+#### Source
538 ++ roll :: left fold
556 ++ roll :: left fold
@@ -543,8 +561,7 @@ Source
544 $(a t.a, b b(+<+ (b i.a +<+.b)))
562 $(a t.a, b b(+<+ (b i.a +<+.b)))
546−Examples
564+#### Examples
549 > =sum =|([p=@ q=@] |.((add p q)))
566 > =sum =|([p=@ q=@] |.((add p q)))
550 > (roll (limo [1 2 3 4 5 ~]) sum)
567 > (roll (limo [1 2 3 4 5 ~]) sum)
@@ -563,21 +580,20 @@ Examples
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
567the front of the list.
584the front of the list.
569−Accepts
586+#### Accepts
572`b` is a list.
590`b` is a list.
574−Produces
592+#### Produces
577A list of the same type as `b`.
594A list of the same type as `b`.
579−Source
596+#### Source
582 ++ scag :: prefix
598 ++ scag :: prefix
@@ -586,13 +602,13 @@ Source
586 ?: |(?=(~ b) =(0 a)) ~
602 ?: |(?=(~ b) =(0 a)) ~
587 [i.b $(b t.b, a (dec a))]
603 [i.b $(b t.b, a (dec a))]
589−Examples
605+#### Examples
592− > (scag 2 (limo [0 1 2 3 ~]))
607+ > (scag 2 `(list @)`[1 2 3 4 ~])
593− [i=0 t=[i=1 t=~]]
608+ [i=0 t=~[1]]
594− > (scag 10 (limo [1 2 3 4 ~]))
610+ > (scag 10 `(list @)`[1 2 3 4 ~])
595− [i=1 t=[i=2 t=[i=3 t=[i=4 t=~]]]]
611+ [i=1 t=~[2 3 4]]
@@ -601,25 +617,27 @@ Examples
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
605true when slammed to gate `b` and those who produce `%.n`.
621true when slammed to gate `b` and those who produce `%.n`.
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`.)
607−Accepts
626+#### Accepts
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.
612−Produces
632+#### Produces
615A cell of two lists.
634A cell of two lists.
617−Source
636+#### Source
620 ++ skid :: separate
638 ++ skid :: separate
622− |* {a/(list) b/$-(* ?)}
640+ |* [a=(list) b=$-(* ?)]
623 |- ^+ [p=a q=a]
641 |- ^+ [p=a q=a]
624 ?~ a [~ ~]
642 ?~ a [~ ~]
625 =+ c=$(a t.a)
643 =+ c=$(a t.a)
@@ -627,12 +645,11 @@ Source
630−Examples
648+#### Examples
633− > =a |=(a/@ (gth a 1))
650+ > =a |=(a=@ (gth a 1))
634− > (skid (limo [0 1 2 3 ~]) a)
651+ > (skid `(list @)`[0 1 2 3 ~]) a)
635− [p=[i=2 t=[i=3 t=~]] q=[i=0 t=[i=1 t=~]]]
652+ (skid `(list @)`[0 1 2 3 ~]) a)
@@ -643,36 +660,34 @@ Suffix
644Cycles through the members of a list `a`, passing them to a gate `b` and
661Cycles 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
662producing a list of all of the members that produce `%.y`. Inverse of
648−Accepts
665+#### Accepts
651`b` is a gate that accepts one argument and produces a boolean.
669`b` is a gate that accepts one argument and produces a boolean.
653−Produces
671+#### Produces
658−Source
675+#### Source
661 ++ skim :: only
677 ++ skim :: only
663− |* {a/(list) b/$-(* ?)}
679+ |* [a=(list) b=$-(* ?)]
667 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
683 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
670−Examples
686+#### Examples
673− > =a |=(a/@ (gth a 1))
688+ > =a |=(a=@ (gth a 1))
674− > (skim (limo [0 1 2 3 ~]) a)
689+ > (skim `(list @)`[0 1 2 3 ~] a)
675− [i=2 t=[i=3 t=~]]
690+ [i=2 t=~[3]]
@@ -681,37 +696,35 @@ Examples
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`.
685Produces a list of all of the members that produce `%.n`. Inverse of
700Produces a list of all of the members that produce `%.n`. Inverse of
688−Accepts
703+#### Accepts
691−`b` is a gate that accepts one argument and produces a loobean.
705+`a` is a list.
707+`b` is a gate that accepts one argument and produces a flag.
693−Produces
709+#### Produces
696A list of the same type as `a`.
711A list of the same type as `a`.
698−Source
713+#### Source
701 ++ skip :: except
715 ++ skip :: except
703− |* {a/(list) b/$-(* ?)}
717+ |* [a=(list) b=$-(* ?)]
707 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
721 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
710−Examples
724+#### Examples
713− > =a |=(a/@ (gth a 1))
726+ > =a |=(a=@ (gth a 1))
714− > (skip (limo [0 1 2 3 ~]) a)
727+ > (skip `(l)`[0 1 2 3 ~]) a)
715 [i=0 t=[i=1 t=~]]
728 [i=0 t=[i=1 t=~]]
@@ -724,30 +737,26 @@ Suffix
724Accepts an atom `a` and list `b`, producing the remaining elements from
737Accepts an atom `a` and list `b`, producing the remaining elements from
725`b` starting at `a`.
738`b` starting at `a`.
727−Accepts
740+#### Accepts
730`b` is a list.
742`b` is a list.
732−Produces
744+#### Produces
735A list of the same type as `b`.
746A list of the same type as `b`.
737−Source
748+#### Source
740 ++ slag :: suffix
750 ++ slag :: suffix
742− |* {a/@ b/(list)}
752+ |* [a=@ b=(list)]
744 ?: =(0 a) b
754 ?: =(0 a) b
746 $(b t.b, a (dec a))
756 $(b t.b, a (dec a))
749−Examples
759+#### Examples
752 > (slag 2 (limo [1 2 3 4 ~]))
761 > (slag 2 (limo [1 2 3 4 ~]))
753 [i=3 t=[i=4 t=~]]
762 [i=3 t=[i=4 t=~]]
@@ -764,22 +773,19 @@ Index
764Accepts an atom `a` and a `++list` `b`, producing the element at the index
773Accepts 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.
774of `a`and failing if the list is null. Lists are 0-indexed.
767−Accepts
776+#### Accepts
770`b` is a list.
778`b` is a list.
772−Produces
780+#### Produces
775Produces an element of `b`, or crashes if no element exists at that index.
782Produces an element of `b`, or crashes if no element exists at that index.
777−Source
784+#### Source
780 ++ snag :: index
786 ++ snag :: index
782− |* {a/@ b/(list)}
788+ |* [a=@ b=(list)]
785 ~|('snag-fail' !!)
791 ~|('snag-fail' !!)
@@ -787,8 +793,7 @@ Source
787 $(b t.b, a (dec a))
793 $(b t.b, a (dec a))
790−Examples
796+#### Examples
793 > (snag 2 "asdf")
798 > (snag 2 "asdf")
@@ -803,25 +808,22 @@ Examples
805Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
810Quicksort: 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`,
807sorted according to `b`.
812sorted according to `b`.
809−Accepts
814+#### Accepts
812`b` is a gate that accepts two nouns and produces a boolean.
816`b` is a gate that accepts two nouns and produces a boolean.
814−Produces
818+#### Produces
819−Source
822+#### Source
822 ++ sort !. :: quicksort
824 ++ sort !. :: quicksort
824− |* {a/(list) b/$-([* *] ?)}
826+ |* [a=(list) b=$-([* *] ?)]
825 => .(a ^.(homo a))
827 => .(a ^.(homo a))
@@ -831,91 +833,14 @@ Source
831 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
833 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
834−Examples
836+#### Examples
837− > =a =|({p/@ q/@} |.((gth p q)))
838+ > =a =|([p/@ q/@] |.((gth p q)))
838 > (sort (limo [0 1 2 3 ~]) a)
839 > (sort (limo [0 1 2 3 ~]) a)
839 ~[3 2 1 0]
840 ~[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`
845### `++spin`
@@ -927,8 +852,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
852should produce a tuple of the transformed element and the (potentially
928modified) state `c`.
853modified) state `c`.
930−Accepts
855+#### Accepts
933`a` is a `++list`.
857`a` is a `++list`.
@@ -936,49 +860,43 @@ Accepts
937`c` is a noun.
861`c` is a noun.
939−Produces
863+#### Produces
944−Source
867+#### Source
948− |* {a/(list) b/_|=({* *} [** +<+]) c/*}
871+ |* [a=(list) b=* c=_|=(^ [** +<+])]
949− :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
872+ => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
950− |-
873+ =/ acc=(list _-:(c)) ~
874+ |- ^- (pair _acc _b)
952− ~
876+ [(flop acc) b]
953− =+ v=(b i.a c)
877+ =^ res b (c i.a b)
954− [i=-.v t=$(a t.a, c +.v)]
878+ $(acc [res acc], a t.a)
957−Examples
881+#### Examples
960−A trivial example -- does nothing with the state:
962− > %^ spin (limo ~[4 5 6])
884+ > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
963− |=({n/@ a/@} [n a])
885+ |=([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])
889+ > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
970− |=({n/@ a/@} [`(pair)`[a n] +(a)])
890+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
972 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
892 ~[[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)
894+ > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
977− |=({n/@ rng/_og} (rads:rng 10))
895+ |=([n=@ rng=_og] (rads:rng 10))
978 ~(. og eny)
896 ~(. og eny)
979 ~[5 5 9 4 1 7 9 9 9 6]
897 ~[5 5 9 4 1 7 9 9 9 6]
981−*Notes*:
899+#### Discussion
983`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
901`(~(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
902with entropy (`eny`). The head of the product is the random number, the tail
@@ -991,57 +909,115 @@ is the continuation of the RNG.
992Gate to list, with state
910Gate to list, with state
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
995derived by *bunting* the tail of the sample of gate `b`, instead of
913derived by *bunting* the tail of the sample of gate `b`, instead of
996being passed in explicitly as in `++spin`. Produces a list with the
914being 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
915+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
916+ 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)
917produce a tuple of the transformed element and the (potentially modified)
1000state `c`.
918state `c`.
1002−Accepts
920+#### Accepts
1005`a` is a `++list`.
922`a` is a `++list`.
1007`b` is a gate.
924`b` is a gate.
1009−Produces
926+#### Produces
1014−Source
930+#### Source
1018− |* {a/(list) b/_|=({* *} [** +<+])}
934+ |* [a=(list) b=_|=(^ [** +<+])]
1019− =| c/_+<+.b
935+ p:(spin a +<+.b b)
1024− [i=-.v t=$(a t.a, c +.v)]
1030−Create a list of pairs, `p` as the index and `q` as the list element:
938+#### Examples
1032− > %+ spun (limo ~[4 5 6])
940+ > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
1033− |=({n/@ a/@} [`(pair)`[a n] +(a)])
941+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
1034 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
942 ~[[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:
1038− > =l (limo ~[7 8 9])
944+ > =l (limo ~[7 8 9])
1039− > %+ spun (limo ~[4 5 6])
945+ > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
1040− |=({n/@ a/@} [`(pair)`[(snag a l) n] +(a)])
946+ |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1041 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
947 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
956+Similar to `substr` in Javascript: extracts a string infix, beginning at
957+inclusive index `a`, producing `b` number of characters.
965+A list of the same type as `c`.
970+ |* [[a=@ a=@] c=(list)]
971+ (scag +<-> (slag +<-< c))
976+ > (swag [2 5] "roly poly")
979+ > (swag [2 2] (limo [1 2 3 4 ~]))
989+Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
990+to each element of the original list.
1004+ |* [a=(list) b=gate]
1007+ [i=(b i.a) t=$(a t.a)]
1012+ > (turn (limo [104 111 111 110 ~]) @t)
1015+ > =a |=(a=@ (add a 4))
1016+ > (turn (limo [1 2 3 4 ~]) a)
1046### `++weld`
1022### `++weld`
@@ -1049,28 +1025,26 @@ Concatenate
1050Concatenate two `++list`s `a` and `b`.
1026Concatenate two `++list`s `a` and `b`.
1052−Accepts
1028+#### Accepts
1055`a` and `b` are lists.
1030`a` and `b` are lists.
1057−Source
1032+#### Source
1060− ++ weld :: concatenate
1034+ ++ weld
1061 ~/ %weld
1035 ~/ %weld
1062− |* {a/(list) b/(list)}
1036+ |* [a=(list) b=(list)]
1063 => .(a ^.(homo a), b ^.(homo b))
1037 => .(a ^.(homo a), b ^.(homo b))
1066 [i.a $(a t.a)]
1040 [i.a $(a t.a)]
1069−Examples
1043+#### Examples
1072 > (weld "urb" "it")
1045 > (weld "urb" "it")
1073 ~[~~u ~~r ~~b ~~i ~~t]
1046 ~[~~u ~~r ~~b ~~i ~~t]
1074 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1048 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1075 ~[1 2 3 4]
1049 ~[1 2 3 4]
@@ -1084,23 +1058,20 @@ Perfect weld
1084Concatenate two `++list`s `a` and `b` without losing their type information
1058Concatenate two `++list`s `a` and `b` without losing their type information
1085to homogenization.
1059to homogenization.
1087−Accepts
1061+#### Accepts
1090`a` is a list.
1063`a` is a list.
1092`b` is a list.
1065`b` is a list.
1094−Produces
1067+#### Produces
1099−Source
1071+#### Source
1102− ++ welp :: perfect weld
1073+ ++ welp
1103− =| {* *}
1074+ =| [* *]
@@ -1109,18 +1080,20 @@ Source
1112−Examples
1083+#### Examples
1115 > (welp "foo" "bar")
1085 > (welp "foo" "bar")
1116 "foobar"
1086 "foobar"
1117− ~zod/arvo=/hoon/hoon> (welp ~[60 61 62] ~[%a %b %c])
1088+ > (welp ~[60 61 62] ~[%a %b %c])
1118 [60 61 62 %a %b %c ~]
1089 [60 61 62 %a %b %c ~]
1119− ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1091+ > ? (welp ~[60 61 62] ~[%a %b %c])
1092+ {@ud @ud @ud $a $b $c $~}
1120 [60 61 62 %a %b %c ~]
1093 [60 61 62 %a %b %c ~]
1121− [@ud @ud @ud %a %b %c %~]
1094+
1122− ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si/3)
1095+ > (welp [sa+1 so+2 ~] si=3)
1123− [[%sa 1] [%so 2] %si 3]
1096+ [[%sa 1] [%so 2] si=3]
@@ -1132,20 +1105,17 @@ Cons
1132Turns a `++list` of lists into a single list by promoting the elements of
1105Turns a `++list` of lists into a single list by promoting the elements of
1133each sublist into the higher.
1106each sublist into the higher.
1135−Accepts
1108+#### Accepts
1138A list of lists.
1110A list of lists.
1140−Produces
1112+#### Produces
1145−Source
1116+#### Source
1148− ++ zing :: promote
1118+ ++ zing
@@ -1156,11 +1126,11 @@ Source
1159−Examples
1129+#### Examples
1162 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1131 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1163 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1132 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1164 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1134 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1165 ~[1 97 2 98 3 99 4 100]
1135 ~[1 97 2 98 3 99 4 100]