on cb112e8 help sign in
1412 lines 22 kB history raw
1+++
2title = "2b: List Logic"
3weight = 5
4template = "doc.html"
5+++
7### `++fand`
9All indices in `list`
11Produces the indices of all occurrences of `nedl` in `hstk` as a `list` of
12atoms.
14#### Accepts
16`nedl` is a list.
18`hstk` is a list.
20#### Produces
22A `list`.
24#### Source
26```hoon
27 ++ fand
28 ~/ %fand
29 |= [nedl=(list) hstk=(list)]
30 =| i=@ud
31 =| fnd=(list @ud)
32 |- ^+ fnd
33 =+ [n=nedl h=hstk]
34 |-
35 ?: |(?=($~ n) ?=($~ h))
36 (flop fnd)
37 ?: =(i.n i.h)
38 ?~ t.n
39 ^$(i +(i), hstk +.hstk, fnd [i fnd])
40 $(n t.n, h t.h)
41 ^$(i +(i), hstk +.hstk)
42```
44#### Examples
46```
47 > (fand ~[3] ~[1 2 3])
48 ~[2]
50 > (fand ~[4] ~[1 2 3])
51 ~
53 > (fand ~['a'] "cbabab")
54 ~[2 4]
56 > (fand "ba" "cbabab")
57 ~[1 3]
58```
61---
62### `++find`
64First index in `list`
66Produces the index of the first occurrence of `nedl` in `hstk` as the `unit`
67of an atom.
69#### Accepts
71`nedl` is a list.
73`hstk` is a list.
75#### Produces
77The `unit` of an atom.
79#### Source
81```hoon
82 ++ find
83 ~/ %find
84 |= [nedl=(list) hstk=(list)]
85 =| i=@ud
86 |- ^- (unit @ud)
87 =+ [n=nedl h=hstk]
88 |-
89 ?: |(?=($~ n) ?=($~ h))
90 ~
91 ?: =(i.n i.h)
92 ?~ t.n
93 `i
94 $(n t.n, h t.h)
95 ^$(i +(i), hstk +.hstk)
96```
98#### Examples
100```
101 > (find [3]~ ~[1 2 3])
102 [~ u=2]
104 > (find [4]~ ~[1 2 3])
105 ~
107 > (find ['c']~ "cbabab")
108 [~ u=0]
110 > (find "ab" "cbabab")
111 [~ u=1]
113 > (find "bab" "cbabab")
114 [~ u=2]
115```
117---
118### `++flop`
120Reverse
122Produces the `list` `a` in reverse order.
124#### Accepts
126`a` is a `list`.
128#### Produces
130A `list`.
132#### Source
134```hoon
135 ++ flop
136 ~/ %flop
137 |* a=(list)
138 => .(a (homo a))
139 ^+ a
140 =+ b=`_a`~
141 |-
142 ?~ a b
143 $(a t.a, b [i.a b])
144```
147#### Examples
149```
150 > =a [1 2 3 ~]
151 > (flop a)
152 ~[3 2 1]
154 > (flop (flop a))
155 ~[1 2 3]
156```
158---
159### `++gulf`
161List from range
163Produces a `list` composed of each consecutive integer starting from `a` and
164ending with `b`. `a` and `b` are themselves included.
166#### Accepts
168`a` is an atom.
170`b` is an atom.
172#### Produces
174a `list`.
176#### Source
178```hoon
179 ++ gulf
180 |= [a=@ b=@]
181 ^- (list @)
182 ?:(=(a +(b)) ~ [a $(a +(a))])
183```
185#### Examples
187```
188 > (gulf 1 6)
189 ~[1 2 3 4 5 6]
191 > `(list @t)`(gulf 99 106)
192 <|c d e f g h i j|>
193```
195---
196### `++homo`
198Homogenize
200Produces a `list` whose type is a fork of all the contained types in the
201list `a`. Used when you want to make all the types of the elements of a list the
202same.
204#### Accepts
206`a` is a `list`.
208#### Produces
210a `list`.
212#### Source
214```hoon
215++ homo :: homogenize
216 |* a=(list)
217 ^+ =< $
218 |@ ++ $ ?:(*? ~ [i=(snag 0 a) t=$])
219 --
220 a
221```
223#### Examples
225```
226 > lyst
227 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
229 > (homo lyst)
230 ~[1 97 2 98 [~ u=10]]
232 > =a (limo [1 2 3 ~])
233 > a
234 [i=1 t=[i=2 t=[i=3 t=~]]]
236 > (homo a)
237 ~[1 2 3]
238```
240---
242### `++join`
244Constructs a new `list`, placing `sep` between every element of `lit`.
246#### Accepts
248`sep` is a `noun`.
250`lit` is a `list`.
252#### Produces
254a `list`.
256#### Source
258```hoon
259 ++ join
260 |* [sep=* lit=(list)]
261 =. sep `_?>(?=(^ lit) i.lit)`sep
262 ?~ lit ~
263 =| out=(list _?>(?=(^ lit) i.lit))
264 |- ^+ out
265 ?~ t.lit
266 (flop [i.lit out])
267 $(out [sep i.lit out], lit t.lit)
268```
270#### Examples
272```
273 > (join ' ' "hoon")
274 "h o o n"
276 > (join 0 `(list @)`~[1 2 3])
277 ~[1 0 2 0 3]
278```
280---
281### `++lent`
283List length
285Produces the length of any `list` `a` as an atom.
287#### Accepts
289`a` is a `list`.
291#### Produces
293an atom.
295#### Source
297```hoon
298 ++ lent
299 ~/ %lent
300 |= a=(list)
301 ^- @
302 =+ b=0
303 |-
304 ?~ a b
305 $(a t.a, b +(b))
306```
308#### Examples
310```
311 > (lent [1 2 3 4 ~]))
312 4
314 > (lent [1 'a' 2 'b' (some 10) ~])
315 5
316```
319---
320### `++levy`
322Logical "and" on list
324Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `list` `a`.
326#### Accepts
328`a` is a list.
330`b` is a gate.
332#### Produces
334A boolean.
336#### Source
338```hoon
339 ++ levy
340 ~/ %levy :: all of
341 |* [a=(list) b=$-(* ?)]
342 |- ^- ?
343 ?~ a &
344 ?. (b i.a) |
345 $(a t.a)
346```
348#### Examples
350```
351 > =a |=(a=@ (lte a 1))
352 > (levy `(list @)`[0 1 2 1 ~] a)
353 %.n
355 > =a |=(a=@ (lte a 3))
356 > (levy `(list @)`[0 1 2 1 ~] a)
357 %.y
358```
361---
363### `++lien`
365Logical "or" on list
367Computes the Boolean logical "or" on the results of applying `gate` `b` to
368every element of `++list` `a`.
370#### Accepts
372`a` is a list.
374`b` is a gate.
376#### Source
378```hoon
379 ++ lien
380 ~/ %lien
381 |* [a=(list) b=$-(* ?)]
382 |- ^- ?
383 ?~ a |
384 ?: (b i.a) &
385 $(a t.a)
386```
388#### Examples
390```
391 > =a |=(a=@ (gte a 1))
392 > (lien `(list @)`[0 1 2 1 ~] a)
393 %.y
395 > =a |=(a=@ (gte a 3))
396 > (lien `(list @)`[0 1 2 1 ~]) a)
397 %.n
398```
401---
402### `++limo`
404List Constructor
406Turns a null-terminated tuple into a `list`.
408#### Accepts
410`a` is a null-terminated tuple.
412#### Produces
414A `++list`.
416#### Source
418```hoon
419++ limo :: listify
420 |* a=*
421 ^+ =< $
422 |@ ++ $ ?~(a ~ ?:(*? [i=-.a t=$] $(a +.a)))
423 --
424 a
425```
427#### Examples
429```
430 > (limo [1 2 3 ~])
431 [i=1 t=[i=2 t=[i=3 t=~]]]
432```
435---
436### `++murn`
438Maybe transform
440Passes each member of `list` `a` to gate `b`, which must produce a
441`unit`. Produces a new list with all the results that do not produce
442`~`.
444#### Accepts
446`a` is a list.
448`b` is a gate that produces a unit.
450#### Produces
452A unit.
454#### Source
456```hoon
457 ++ murn :: maybe transform
458 ~/ %murn
459 |* [a=(list) b=$-(* (unit))]
460 |-
461 ?~ a ~
462 =+ c=(b i.a)
463 ?~ c
464 $(a t.a)
465 [i=u.c t=$(a t.a)]
466```
468#### Examples
470```
471 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
472 > (murn `(list @)`[0 1 2 3 ~] a)
473 [i=12 t=[i=13 t=~]]
474```
477---
478### `++oust`
480Remove
482Removes elements from list `c` beginning at inclusive index `a`, removing `b`
483number of elements.
485#### Accepts
487`c` is a list.
489#### Produces
491A `++list`.
493#### Source
495```hoon
496 ++ oust :: remove
497 ~/ %oust
498 |* [[a=@ b=@] c=(list)]
499 (weld (scag a c) (slag (add a b) c))
500```
502#### Examples
504```
505 > (oust [4 5] "good day, urbit!")
506 "good urbit!"
508 > (oust [2 2] `(list @)`[1 2 3 4 ~])
509 ~[1 2]
510```
513---
514### `++reap`
516Replicate
518Replicate: produces a `list` containing `a` copies of `b`.
520#### Accepts
522`a` is an atom.
524`b` is a noun.
526#### Produces
528A list.
530#### Source
532```hoon
533 ++ reap :: replicate
534 ~/ %reap
535 |* [a=@ b=*]
536 |- ^- (list _b)
537 ?~ a ~
538 [b $(a (dec a))]
539```
541#### Examples
543```
544 > (reap 20 %a)
545 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
547 > (reap 5 ~s1)
548 ~[~s1 ~s1 ~s1 ~s1 ~s1]
550 > `@dr`(roll (reap 5 ~s1) add)
551 ~s5
552```
555---
556### `++reel`
558Right fold
560Right fold: moves right to left across a `list` `a`, recursively slamming
561a binary gate `b` with an element from `a` and an accumulator, producing
562the final value of the accumulator.
564(To "slam" means to call a gate and give it a sample/samples. In this instance,
565`a` is the list of samples that are given to the gate b.)
567The initial value of the accumulator is the bunt of `b`'s second argument (`+<+`). This can occasionally produce
568undesired behavior (see examples). If you need more control over the initial
569value, try making use of `$_` and `|:`, or perhaps [`+spin`](#spin) or
570[`+spun`](#spun).
572#### Accepts
574`a` is a list.
576`b` is a binary gate.
578#### Produces
580The accumulator, which is a noun.
582#### Source
584```hoon
585 ++ reel
586 ~/ %reel
587 |* [a=(list) b=_|=([* *] +<+)]
588 |- ^+ +<+.b
589 ?~ a
590 +<+.b
591 (b i.a $(a t.a))
592```
594#### Examples
596```
597 > (reel `(list @)`[1 2 3 4 5 ~] add)
598 15
600 > (reel `(list @)`[6 3 1 ~] sub)
601 4
603 > (reel `(list @)`[3 6 1 ~] sub)
604 ! subtract-underflow
605 ! exit
606```
608`+mul`'s default sample is 1, so calling `+reel` with `+mul` yields the expected behavior:
609```
610> *mul
613> (reel `(list @)`~[1 2 3 4] mul)
61424
615```
616However, if you build a gate that uses `+mul` like so, the sample defaults to 0
617since that is the bunt of `@`:
618```
619> (reel `(list @)`~[1 2 3 4] |=([a=@ b=@] (mul a b)))
621```
622We can fix this with `|:`:
623```
624> (reel `(list @)`~[1 2 3 4] |:([a=1 b=1] (mul a b)))
62524
626```
630---
631### `++roll`
633Left fold
635Left fold: moves left to right across a list `a`, recursively slamming a
636binary gate `b` with an element from the `list` and an accumulator,
637producing the final value of the accumulator.
639(To "slam" means to call a gate and give it a sample/samples. In this instance,
640`a` is the list of samples that are given to the gate b.)
642The initial value of the accumulator is `b`'s second argument (`+<+`). This can
643occasionally produce undesired behavior (see examples). If you need more control
644over the initial value, try making use of `$_` and `|:`, or perhaps
645[`+spin`](#spin) or [`+spun`](#spun).
647#### Accepts
649`a` is a list.
651`b` is a binary gate.
653#### Produces
655The accumulator, which is a noun.
657#### Source
659```hoon
660 ++ roll :: left fold
661 ~/ %roll
662 |* [a=(list) b=_|=([* *] +<+)]
663 |- ^+ +<+.b
664 ?~ a
665 +<+.b
666 $(a t.a, b b(+<+ (b i.a +<+.b)))
667```
669#### Examples
671```
672> (roll `(list @)`[1 2 3 4 5 ~] add)
673q=15
675> (roll `(list @)`[6 3 1 ~] sub)
676! subtract-underflow
677! exit
679> (roll `(list @)`[1 3 6 ~] sub)
680q=4
681```
683`+mul`'s default sample is 1, so calling `+roll` with `+mul` yields the expected behavior:
684```
685> *mul
688> (roll `(list @)`~[1 2 3 4] mul)
68924
690```
691However, if you build a gate that uses `+mul` like so, the sample defaults to 0
692since that is the bunt of `@`:
693```
694> (roll `(list @)`~[1 2 3 4] |=([a=@ b=@] (mul a b)))
696```
697We can fix this with `|:`:
698```
699> (roll `(list @)`~[1 2 3 4] |:([a=1 b=1] (mul a b)))
70024
701```
704---
705### `++scag`
707Prefix
709Accepts an atom `a` and `list` `b`, producing the first `a` elements of
710the front of the list.
712#### Accepts
714`a` is an atom.
716`b` is a list.
718#### Produces
720A list of the same type as `b`.
722#### Source
724```hoon
725 ++ scag :: prefix
726 ~/ %scag
727 |* [a=@ b=(list)]
728 |- ^+ b
729 ?: |(?=(~ b) =(0 a)) ~
730 [i.b $(b t.b, a (dec a))]
731```
733#### Examples
735```
736 > (scag 2 `(list @)`[1 2 3 4 ~])
737 [i=1 t=~[2]]
739 > (scag 10 `(list @)`[1 2 3 4 ~])
740 [i=1 t=~[2 3 4]]
741```
744---
745### `++skid`
747Separate
749Separates a `list` `a` into two lists - Those elements of `a` who produce
750true when slammed to gate `b` and those who produce `%.n`.
752(To "slam" means to call a gate and give it a sample/samples. In this instance,
753`a` is the list of samples that are given to the gate `b`.)
755#### Accepts
757`a` is a list.
759`b` is a gate that accepts one argument and produces a flag.
761#### Produces
763A cell of two lists.
765#### Source
767```hoon
768 ++ skid :: separate
769 ~/ %skid
770 |* [a=(list) b=$-(* ?)]
771 |- ^+ [p=a q=a]
772 ?~ a [~ ~]
773 =+ c=$(a t.a)
774 ?:((b i.a) [[i.a p.c] q.c] [p.c [i.a q.c]])
775```
778#### Examples
780```
781 > =a |=(a=@ (gth a 1))
782 > (skid `(list @)`[0 1 2 3 ~] a)
783 [p=[i=2 t=~[3]] q=[i=0 t=~[1]]]
784```
787---
788### `++skim`
790Suffix
792Cycles through the members of a list `a`, passing them to a gate `b` and
793producing a list of all of the members that produce `%.y`. Inverse of
794`skip`.
796#### Accepts
798`a` is a list.
800`b` is a gate that accepts one argument and produces a boolean.
802#### Produces
804A list.
806#### Source
808```hoon
809 ++ skim :: only
810 ~/ %skim
811 |* [a=(list) b=$-(* ?)]
812 |-
813 ^+ a
814 ?~ a ~
815 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
816```
818#### Examples
820```
821 > =a |=(a=@ (gth a 1))
822 > (skim `(list @)`[0 1 2 3 ~] a)
823 [i=2 t=~[3]]
824```
826---
827### `++skip`
829Except
831Cycles through the members of `list` `a`, passing them to a gate `b`.
832Produces a list of all of the members that produce `%.n`. Inverse of
833`skim`.
835#### Accepts
837`a` is a list.
839`b` is a gate that accepts one argument and produces a flag.
841#### Produces
843A list of the same type as `a`.
845#### Source
847```hoon
848 ++ skip :: except
849 ~/ %skip
850 |* [a=(list) b=$-(* ?)]
851 |-
852 ^+ a
853 ?~ a ~
854 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
855```
857#### Examples
859```
860 > =a |=(a=@ (gth a 1))
861 > (skip `(l)`[0 1 2 3 ~]) a)
862 [i=0 t=[i=1 t=~]]
863```
866---
867### `++slag`
869Suffix
871Accepts an atom `a` and list `b`, producing the remaining elements from
872`b` starting at `a`.
874#### Accepts
876`a` is an atom.
878`b` is a list.
880#### Produces
882A list of the same type as `b`.
884#### Source
886```hoon
887 ++ slag :: suffix
888 ~/ %slag
889 |* [a=@ b=(list)]
890 |- ^+ b
891 ?: =(0 a) b
892 ?~ b ~
893 $(b t.b, a (dec a))
894```
896#### Examples
898```
899 > (slag 2 (limo [1 2 3 4 ~]))
900 [i=3 t=[i=4 t=~]]
901 > (slag 1 (limo [1 2 3 4 ~]))
902 [i=2 t=[i=3 t=[i=4 t=~]]]
903```
906---
907### `++snag`
909Index
911Accepts an atom `a` and a `++list` `b`, producing the element at the index
912of `a`and failing if the list is null. Lists are 0-indexed.
914#### Accepts
916`a` is an atom.
918`b` is a list.
920#### Produces
922Produces an element of `b`, or crashes if no element exists at that index.
924#### Source
926```hoon
927 ++ snag :: index
928 ~/ %snag
929 |* [a=@ b=(list)]
930 |-
931 ?~ b
932 ~|('snag-fail' !!)
933 ?: =(0 a) i.b
934 $(b t.b, a (dec a))
935```
937#### Examples
939```
940 > (snag 2 "asdf")
941 ~~d
942 > (snag 0 `(list @ud)`~[1 2 3 4])
943 1
944```
947---
948### `++snoc`
950Append
952Accepts a `++list` `a` and a noun `b`, producing the list of `b` appended to `a`.
954#### Accepts
956`a` is a list.
958`b` is a noun.
960#### Produces
962Produces a list of `b` appended to `a`.
964#### Source
966```hoon
967 ++ snoc
968 |* [a/(list) b/*]
969 (weld a ^+(a [b]~))
970```
972#### Examples
974```
975 > `tape`(zing (snoc `(list tape)`~["a" "bc" "def"] "g"))
976 "abcdefg"
977 > (snoc `(list @ud)`~[1 2 3] 4)
978 ~[1 2 3 4]
979```
981---
982### `++snap`
984Replace item at index
986Accepts a `list` `a`, an atom `b`, and a noun `c`, producing the list of `a` with the item at index `b` replaced with `c`.
988#### Accepts
990`a` is a list.
992`b` is a atom.
994`c` is a noun.
997#### Produces
999the list of `a` with the item at index `b` replaced with `c`.
1001#### Source
1003```hoon
1004 ++ snap
1005 |* [a/(list) b/@ c/*]
1006 ^+ a
1007 (weld (scag b a) [c (slag +(b) a)])
1008```
1010#### Examples
1012```
1013 > (snap (limo ~[2 3 4]) 1 11)
1014 ~[2 11 4]
1015```
1017---
1018### `++into`
1020Insert item at index
1022Accepts a `list` `a`, an atom `b`, and a noun `c`, producing the list of `a` with the item `c` inserted at index `b`.
1024#### Accepts
1026`a` is a list.
1028`b` is a atom.
1030`c` is a noun.
1033#### Produces
1035the list of `a` with the item `c` inserted at index `b`.
1037#### Source
1039```hoon
1040 ++ into
1041 |* [a/(list) b/@ c/*]
1042 ^+ a
1043 (weld (scag b a) [c (slag b a)])
1044```
1046#### Examples
1048```
1049 > (into (limo ~[2 3 4]) 1 11)
1050 ~[2 11 3 4]
1051```
1053---
1054### `++sort`
1056Quicksort
1058Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
1059produces a flag. `++sort` then produces a list of the elements of `a`,
1060sorted according to `b`.
1062#### Accepts
1064`a` is a list.
1066`b` is a gate that accepts two nouns and produces a boolean.
1068#### Produces
1070A list
1072#### Source
1074```hoon
1075 ++ sort !. :: quicksort
1076 ~/ %sort
1077 |* [a=(list) b=$-([* *] ?)]
1078 => .(a ^.(homo a))
1079 |- ^+ a
1080 ?~ a ~
1081 %+ weld
1082 $(a (skim t.a |=(c/_i.a (b c i.a))))
1083 ^+ t.a
1084 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
1085```
1087#### Examples
1089```
1090 > (sort `(list @)`[0 1 2 3 ~] gth)
1091 ~[3 2 1 0]
1092```
1095---
1096### `++spin` {#spin}
1098Gate to list, with state
1100Accepts a `++list` `a`, some state `b`, and a gate `c`. `c` is called with
1101a tuple -- the head is an element of `a` and the tail is the state `b`, and
1102should produce a tuple of the transformed element and the (potentially
1103modified) state `b`. Produces a pair where the first element is a list of the
1104transformed elements of `a`, and the second element is the final value of `b`.
1106#### Accepts
1108`a` is a `++list`.
1110`b` is a noun.
1112`c` is a gate.
1114#### Produces
1116A pair of a list and a noun.
1118#### Source
1120```hoon
1121 ++ spin
1122 ~/ %spin
1123 |* [a=(list) b=* c=_|=(^ [** +<+])]
1124 => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
1125 =/ acc=(list _-:(c)) ~
1126 |- ^- (pair _acc _b)
1127 ?~ a
1128 [(flop acc) b]
1129 =^ res b (c i.a b)
1130 $(acc [res acc], a t.a)
1131```
1133#### Examples
1135```
1136 > %^ spin (limo ~[4 5 6]) :: Trivial example -- does nothing with the state
1138 |=([n=@ a=@] [n a])
1139 [p=~[4 5 6] q=0]
1141 > %^ spin (limo ~[4 5 6]) :: Form a pair with `p` as the index and `q` as the list element
1143 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1144 [p=~[[p=0 q=4] [p=1 q=5] [p=2 q=6]] q=3]
1146 > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
1147 ~(. og eny)
1148 |=([n=@ rng=_og] (rads:rng 10))
1149 [p=~[7 8 6 0 1 5 4 7 9 3] q=<4.rvi {a/@uvJ <51.qyl 129.pdd 41.mac 1.ane $141>}>]
1150```
1152#### Discussion
1154`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
1155with entropy (`eny`). The head of the product is the random number, the tail
1156is the continuation of the RNG.
1160---
1161### `++spun` {#spun}
1163Gate to list, with state
1165Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
1166derived by **bunting** the tail of the sample of gate `b`, instead of
1167being passed in explicitly as in `++spin`. Produces a list with the
1168gate applied to each element of the original list. `b` is called with a tuple --
1169the head is an element of `a` and the tail is the state `c`, and should
1170produce a tuple of the transformed element and the (potentially modified)
1171state `c`.
1173#### Accepts
1175`a` is a `++list`.
1177`b` is a gate.
1179#### Produces
1181A list.
1183#### Source
1185```hoon
1186 ++ spun
1187 ~/ %spun
1188 |* [a=(list) b=_|=(^ [** +<+])]
1189 p:(spin a +<+.b b)
1190```
1192#### Examples
1194```
1195 > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
1196 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1197 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1199 > =l (limo ~[7 8 9])
1200 > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
1201 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1202 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1203```
1206---
1207### `++swag`
1209Infix
1211Similar to `substr` in Javascript: extracts a string infix, beginning at
1212inclusive index `a`, producing `b` number of characters.
1214#### Accepts
1216`a` is an atom.
1218`b` is an atom.
1220`c` is a list.
1222#### Produces
1224A list of the same type as `c`.
1226#### Source
1228```hoon
1229 ++ swag
1230 |* [[a=@ b=@] c=(list)]
1231 (scag +<-> (slag +<-< c))
1232```
1234#### Examples
1236```
1237 > (swag [2 5] "roly poly")
1238 "ly po"
1240 > (swag [2 2] (limo [1 2 3 4 ~]))
1241 [i=3 t=[i=4 t=~]]
1242```
1245---
1246### `++turn`
1248Gate to list
1250Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
1251to each element of the original list.
1253#### Accepts
1255`a` is a list.
1257`b` is a gate.
1259#### Produces
1261A list.
1263#### Source
1265```hoon
1266 ++ turn
1267 ~/ %turn
1268 |* [a=(list) b=gate]
1269 |-
1270 ?~ a ~
1271 [i=(b i.a) t=$(a t.a)]
1272```
1274#### Examples
1276```
1277 > (turn (limo [104 111 111 110 ~]) @t)
1278 <|h o o n|>
1280 > =a |=(a=@ (add a 4))
1281 > (turn (limo [1 2 3 4 ~]) a)
1282 ~[5 6 7 8]
1283```
1285#### Discussion
1287`turn` is Hoon's version of 'map' in Haskell.
1289---
1290### `++weld`
1292Concatenate
1294Concatenate two `++list`s `a` and `b`.
1296#### Accepts
1298`a` and `b` are lists.
1300#### Source
1302```hoon
1303 ++ weld
1304 ~/ %weld
1305 |* [a=(list) b=(list)]
1306 => .(a ^.(homo a), b ^.(homo b))
1307 |- ^+ b
1308 ?~ a b
1309 [i.a $(a t.a)]
1310```
1312#### Examples
1314```
1315 > (weld "urb" "it")
1316 "urbit"
1318 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1319 ~[1 2 3 4]
1320```
1323---
1324### `++welp`
1326Perfect weld
1328Concatenate two `++list`s `a` and `b` without losing their type information
1329to homogenization.
1331#### Accepts
1333`a` is a list.
1335`b` is a list.
1337#### Produces
1339A list.
1341#### Source
1343```hoon
1344++ welp :: faceless weld
1345 ~/ %welp
1346 =| [* *]
1347 |@
1348 ++ $
1349 ?~ +<-
1350 +<-(. +<+)
1351 +<-(+ $(+<- +<->))
1352 --
1353```
1355#### Examples
1357```
1358 > (welp "foo" "bar")
1359 "foobar"
1361 > (welp ~[60 61 62] ~[%a %b %c])
1362 [60 61 62 %a %b %c ~]
1364 > ? (welp ~[60 61 62] ~[%a %b %c])
1365 {@ud @ud @ud $a $b $c $~}
1366 [60 61 62 %a %b %c ~]
1368 > (welp [sa+1 so+2 ~] si=3)
1369 [[%sa 1] [%so 2] si=3]
1370```
1373---
1374### `++zing`
1376Turns a `++list` of lists into a single list by promoting the elements of
1377each sublist into the higher.
1379#### Accepts
1381A list of lists.
1383#### Produces
1385A list.
1387#### Source
1389```hoon
1390++ zing :: promote
1391 ~/ %zing
1392 =| *
1393 |@
1394 ++ $
1395 ?~ +<
1396 +<
1397 (welp +<- $(+< +<+))
1398 --
1399```
1402#### Examples
1404```
1405 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1406 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1408 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1409 ~[1 97 2 98 3 99 4 100]
1410```
1412---