on 58456ea help sign in
1364 lines 20 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
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.)
567#### Accepts
569`a` is a list.
571`b` is a binary gate.
573#### Produces
575The accumulator, which is a noun.
577#### Source
579```hoon
580 ++ reel
581 ~/ %reel
582 |* [a=(list) b=_|=([* *] +<+)]
583 |- ^+ +<+.b
584 ?~ a
585 +<+.b
586 (b i.a $(a t.a))
587```
589#### Examples
591```
592 > =sum =|([p=@ q=@] |.((add p q)))
593 > (reel (limo [1 2 3 4 5 ~]) sum)
594 15
596 > =a =|([p=@ q=@] |.((sub p q)))
597 > (reel (limo [6 3 1 ~]) a)
598 4
600 > (reel (limo [3 6 1 ~]) a)
601 ! subtract-underflow
602 ! exit
603```
606---
607### `++roll`
609Left fold
611Left fold: moves left to right across a list `a`, recursively slamming a
612binary gate `b` with an element from the `list` and an accumulator,
613producing the final value of the accumulator.
615(To "slam" means to call a gate and give it a sample/samples. In this instance,
616`a` is the list of samples that are given to the gate b.)
618#### Accepts
620`a` is a list.
622`b` is a binary gate.
624#### Produces
626The accumulator, which is a noun.
628#### Source
630```hoon
631 ++ roll :: left fold
632 ~/ %roll
633 |* [a=(list) b=_|=([* *] +<+)]
634 |- ^+ +<+.b
635 ?~ a
636 +<+.b
637 $(a t.a, b b(+<+ (b i.a +<+.b)))
638```
640#### Examples
642```
643 > =sum =|([p=@ q=@] |.((add p q)))
644 > (roll (limo [1 2 3 4 5 ~]) sum)
645 q=15
647 > =a =|([p=@ q=@] |.((sub p q)))
648 > (roll (limo [6 3 1 ~]) a)
649 ! subtract-underflow
650 ! exit
652 > (roll (limo [1 3 6 ~]) a)
653 q=4
654```
657---
658### `++scag`
660Prefix
662Accepts an atom `a` and `list` `b`, producing the first `a` elements of
663the front of the list.
665#### Accepts
667`a` is an atom.
669`b` is a list.
671#### Produces
673A list of the same type as `b`.
675#### Source
677```hoon
678 ++ scag :: prefix
679 ~/ %scag
680 |* [a=@ b=(list)]
681 |- ^+ b
682 ?: |(?=(~ b) =(0 a)) ~
683 [i.b $(b t.b, a (dec a))]
684```
686#### Examples
688```
689 > (scag 2 `(list @)`[1 2 3 4 ~])
690 [i=1 t=~[2]]
692 > (scag 10 `(list @)`[1 2 3 4 ~])
693 [i=1 t=~[2 3 4]]
694```
697---
698### `++skid`
700Separate
702Separates a `list` `a` into two lists - Those elements of `a` who produce
703true when slammed to gate `b` and those who produce `%.n`.
705(To "slam" means to call a gate and give it a sample/samples. In this instance,
706`a` is the list of samples that are given to the gate `b`.)
708#### Accepts
710`a` is a list.
712`b` is a gate that accepts one argument and produces a flag.
714#### Produces
716A cell of two lists.
718#### Source
720```hoon
721 ++ skid :: separate
722 ~/ %skid
723 |* [a=(list) b=$-(* ?)]
724 |- ^+ [p=a q=a]
725 ?~ a [~ ~]
726 =+ c=$(a t.a)
727 ?:((b i.a) [[i.a p.c] q.c] [p.c [i.a q.c]])
728```
731#### Examples
733```
734 > =a |=(a=@ (gth a 1))
735 > (skid `(list @)`[0 1 2 3 ~] a)
736 [p=[i=2 t=~[3]] q=[i=0 t=~[1]]]
737```
740---
741### `++skim`
743Suffix
745Cycles through the members of a list `a`, passing them to a gate `b` and
746producing a list of all of the members that produce `%.y`. Inverse of
747`skip`.
749#### Accepts
751`a` is a list.
753`b` is a gate that accepts one argument and produces a boolean.
755#### Produces
757A list.
759#### Source
761```hoon
762 ++ skim :: only
763 ~/ %skim
764 |* [a=(list) b=$-(* ?)]
765 |-
766 ^+ a
767 ?~ a ~
768 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
769```
771#### Examples
773```
774 > =a |=(a=@ (gth a 1))
775 > (skim `(list @)`[0 1 2 3 ~] a)
776 [i=2 t=~[3]]
777```
779---
780### `++skip`
782Except
784Cycles through the members of `list` `a`, passing them to a gate `b`.
785Produces a list of all of the members that produce `%.n`. Inverse of
786`skim`.
788#### Accepts
790`a` is a list.
792`b` is a gate that accepts one argument and produces a flag.
794#### Produces
796A list of the same type as `a`.
798#### Source
800```hoon
801 ++ skip :: except
802 ~/ %skip
803 |* [a=(list) b=$-(* ?)]
804 |-
805 ^+ a
806 ?~ a ~
807 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
808```
810#### Examples
812```
813 > =a |=(a=@ (gth a 1))
814 > (skip `(l)`[0 1 2 3 ~]) a)
815 [i=0 t=[i=1 t=~]]
816```
819---
820### `++slag`
822Suffix
824Accepts an atom `a` and list `b`, producing the remaining elements from
825`b` starting at `a`.
827#### Accepts
829`a` is an atom.
831`b` is a list.
833#### Produces
835A list of the same type as `b`.
837#### Source
839```hoon
840 ++ slag :: suffix
841 ~/ %slag
842 |* [a=@ b=(list)]
843 |- ^+ b
844 ?: =(0 a) b
845 ?~ b ~
846 $(b t.b, a (dec a))
847```
849#### Examples
851```
852 > (slag 2 (limo [1 2 3 4 ~]))
853 [i=3 t=[i=4 t=~]]
854 > (slag 1 (limo [1 2 3 4 ~]))
855 [i=2 t=[i=3 t=[i=4 t=~]]]
856```
859---
860### `++snag`
862Index
864Accepts an atom `a` and a `++list` `b`, producing the element at the index
865of `a`and failing if the list is null. Lists are 0-indexed.
867#### Accepts
869`a` is an atom.
871`b` is a list.
873#### Produces
875Produces an element of `b`, or crashes if no element exists at that index.
877#### Source
879```hoon
880 ++ snag :: index
881 ~/ %snag
882 |* [a=@ b=(list)]
883 |-
884 ?~ b
885 ~|('snag-fail' !!)
886 ?: =(0 a) i.b
887 $(b t.b, a (dec a))
888```
890#### Examples
892```
893 > (snag 2 "asdf")
894 ~~d
895 > (snag 0 `(list @ud)`~[1 2 3 4])
896 1
897```
900---
901### `++snoc`
903Append
905Accepts a `++list` `a` and a noun `b`, producing the list of `b` appended to `a`.
907#### Accepts
909`a` is a list.
911`b` is a noun.
913#### Produces
915Produces a list of `b` appended to `a`.
917#### Source
919```hoon
920 ++ snoc
921 |* [a/(list) b/*]
922 (weld a ^+(a [b]~))
923```
925#### Examples
927```
928 > `tape`(zing (snoc `(list tape)`~["a" "bc" "def"] "g"))
929 "abcdefg"
930 > (snoc `(list @ud)`~[1 2 3] 4)
931 ~[1 2 3 4]
932```
934---
935### `++snap`
937Replace item at index
939Accepts a `list` `a`, an atom `b`, and a noun `c`, producing the list of `a` with the item at index `b` replaced with `c`.
941#### Accepts
943`a` is a list.
945`b` is a atom.
947`c` is a noun.
950#### Produces
952the list of `a` with the item at index `b` replaced with `c`.
954#### Source
956```hoon
957 ++ snap
958 |* [a/(list) b/@ c/*]
959 ^+ a
960 (weld (scag b a) [c (slag +(b) a)])
961```
963#### Examples
965```
966 > (snap (limo ~[2 3 4]) 1 11)
967 ~[2 11 4]
968```
970---
971### `++into`
973Insert item at index
975Accepts a `list` `a`, an atom `b`, and a noun `c`, producing the list of `a` with the item `c` inserted at index `b`.
977#### Accepts
979`a` is a list.
981`b` is a atom.
983`c` is a noun.
986#### Produces
988the list of `a` with the item `c` inserted at index `b`.
990#### Source
992```hoon
993 ++ into
994 |* [a/(list) b/@ c/*]
995 ^+ a
996 (weld (scag b a) [c (slag b a)])
997```
999#### Examples
1001```
1002 > (into (limo ~[2 3 4]) 1 11)
1003 ~[2 11 3 4]
1004```
1006---
1007### `++sort`
1009Quicksort
1011Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
1012produces a flag. `++sort` then produces a list of the elements of `a`,
1013sorted according to `b`.
1015#### Accepts
1017`a` is a list.
1019`b` is a gate that accepts two nouns and produces a boolean.
1021#### Produces
1023A list
1025#### Source
1027```hoon
1028 ++ sort !. :: quicksort
1029 ~/ %sort
1030 |* [a=(list) b=$-([* *] ?)]
1031 => .(a ^.(homo a))
1032 |- ^+ a
1033 ?~ a ~
1034 %+ weld
1035 $(a (skim t.a |=(c/_i.a (b c i.a))))
1036 ^+ t.a
1037 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
1038```
1040#### Examples
1042```
1043 > =a =|([p/@ q/@] |.((gth p q)))
1044 > (sort (limo [0 1 2 3 ~]) a)
1045 ~[3 2 1 0]
1046```
1049---
1050### `++spin`
1052Gate to list, with state
1054Accepts a `++list` `a`, a gate `b`, and some state `c`. Produces a list with
1055the gate applied to each element of the original list. `b` is called with
1056a tuple -- the head is an element of `a` and the tail is the state `c`, and
1057should produce a tuple of the transformed element and the (potentially
1058modified) state `c`.
1060#### Accepts
1062`a` is a `++list`.
1064`b` is a gate.
1066`c` is a noun.
1068#### Produces
1070A list.
1072#### Source
1074```hoon
1075 ++ spin
1076 ~/ %spin
1077 |* [a=(list) b=* c=_|=(^ [** +<+])]
1078 => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
1079 =/ acc=(list _-:(c)) ~
1080 |- ^- (pair _acc _b)
1081 ?~ a
1082 [(flop acc) b]
1083 =^ res b (c i.a b)
1084 $(acc [res acc], a t.a)
1085```
1087#### Examples
1089```
1090 > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
1091 |=([n=@ a=@] [n a])
1093 ~[4 5 6]
1095 > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
1096 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1098 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1100 > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
1101 |=([n=@ rng=_og] (rads:rng 10))
1102 ~(. og eny)
1103 ~[5 5 9 4 1 7 9 9 9 6]
1104```
1106#### Discussion
1108`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
1109with entropy (`eny`). The head of the product is the random number, the tail
1110is the continuation of the RNG.
1114---
1115### `++spun`
1117Gate to list, with state
1119Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
1120derived by **bunting** the tail of the sample of gate `b`, instead of
1121being passed in explicitly as in `++spin`. Produces a list with the
1122gate applied to each element of the original list. `b` is called with a tuple --
1123the head is an element of `a` and the tail is the state `c`, and should
1124produce a tuple of the transformed element and the (potentially modified)
1125state `c`.
1127#### Accepts
1129`a` is a `++list`.
1131`b` is a gate.
1133#### Produces
1135A list.
1137#### Source
1139```hoon
1140 ++ spun
1141 ~/ %spun
1142 |* [a=(list) b=_|=(^ [** +<+])]
1143 p:(spin a +<+.b b)
1144```
1146#### Examples
1148```
1149 > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
1150 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1151 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1153 > =l (limo ~[7 8 9])
1154 > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
1155 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1156 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1157```
1160---
1161### `++swag`
1163Infix
1165Similar to `substr` in Javascript: extracts a string infix, beginning at
1166inclusive index `a`, producing `b` number of characters.
1168#### Accepts
1170`a` is an atom.
1172`b` is an atom.
1174`c` is a list.
1176#### Produces
1178A list of the same type as `c`.
1180#### Source
1182```hoon
1183 ++ swag
1184 |* [[a=@ b=@] c=(list)]
1185 (scag +<-> (slag +<-< c))
1186```
1188#### Examples
1190```
1191 > (swag [2 5] "roly poly")
1192 "ly po"
1194 > (swag [2 2] (limo [1 2 3 4 ~]))
1195 [i=3 t=[i=4 t=~]]
1196```
1199---
1200### `++turn`
1202Gate to list
1204Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
1205to each element of the original list.
1207#### Accepts
1209`a` is a list.
1211`b` is a gate.
1213#### Produces
1215A list.
1217#### Source
1219```hoon
1220 ++ turn
1221 ~/ %turn
1222 |* [a=(list) b=gate]
1223 |-
1224 ?~ a ~
1225 [i=(b i.a) t=$(a t.a)]
1226```
1228#### Examples
1230```
1231 > (turn (limo [104 111 111 110 ~]) @t)
1232 <|h o o n|>
1234 > =a |=(a=@ (add a 4))
1235 > (turn (limo [1 2 3 4 ~]) a)
1236 ~[5 6 7 8]
1237```
1239#### Discussion
1241`turn` is Hoon's version of 'map' in Haskell.
1243---
1244### `++weld`
1246Concatenate
1248Concatenate two `++list`s `a` and `b`.
1250#### Accepts
1252`a` and `b` are lists.
1254#### Source
1256```hoon
1257 ++ weld
1258 ~/ %weld
1259 |* [a=(list) b=(list)]
1260 => .(a ^.(homo a), b ^.(homo b))
1261 |- ^+ b
1262 ?~ a b
1263 [i.a $(a t.a)]
1264```
1266#### Examples
1268```
1269 > (weld "urb" "it")
1270 ~[~~u ~~r ~~b ~~i ~~t]
1272 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1273 ~[1 2 3 4]
1274```
1277---
1278### `++welp`
1280Perfect weld
1282Concatenate two `++list`s `a` and `b` without losing their type information
1283to homogenization.
1285#### Accepts
1287`a` is a list.
1289`b` is a list.
1291#### Produces
1293A list.
1295#### Source
1297```hoon
1298 ++ welp
1299 =| [* *]
1300 |%
1301 +- $
1302 ?~ +<-
1303 +<-(. +<+)
1304 +<-(+ $(+<- +<->))
1305 --
1306```
1308#### Examples
1310```
1311 > (welp "foo" "bar")
1312 "foobar"
1314 > (welp ~[60 61 62] ~[%a %b %c])
1315 [60 61 62 %a %b %c ~]
1317 > ? (welp ~[60 61 62] ~[%a %b %c])
1318 {@ud @ud @ud $a $b $c $~}
1319 [60 61 62 %a %b %c ~]
1321 > (welp [sa+1 so+2 ~] si=3)
1322 [[%sa 1] [%so 2] si=3]
1323```
1326---
1327### `++zing`
1329Turns a `++list` of lists into a single list by promoting the elements of
1330each sublist into the higher.
1332#### Accepts
1334A list of lists.
1336#### Produces
1338A list.
1340#### Source
1342```hoon
1343 ++ zing
1344 =| *
1345 |%
1346 +- $
1347 ?~ +<
1348 +<
1349 (welp +<- $(+< +<+))
1350 --
1351```
1354#### Examples
1356```
1357 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1358 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1360 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1361 ~[1 97 2 98 3 99 4 100]
1362```
1364---