on 89a2e21 help sign in
1359 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 > (reel `(list @)`[1 2 3 4 5 ~] add)
593 15
595 > (reel `(list @)`[6 3 1 ~] sub)
596 4
598 > (reel `(list @)`[3 6 1 ~] sub)
599 ! subtract-underflow
600 ! exit
601```
604---
605### `++roll`
607Left fold
609Left fold: moves left to right across a list `a`, recursively slamming a
610binary gate `b` with an element from the `list` and an accumulator,
611producing the final value of the accumulator.
613(To "slam" means to call a gate and give it a sample/samples. In this instance,
614`a` is the list of samples that are given to the gate b.)
616#### Accepts
618`a` is a list.
620`b` is a binary gate.
622#### Produces
624The accumulator, which is a noun.
626#### Source
628```hoon
629 ++ roll :: left fold
630 ~/ %roll
631 |* [a=(list) b=_|=([* *] +<+)]
632 |- ^+ +<+.b
633 ?~ a
634 +<+.b
635 $(a t.a, b b(+<+ (b i.a +<+.b)))
636```
638#### Examples
640```
641 > (roll `(list @)`[1 2 3 4 5 ~] add)
642 q=15
644 > (roll `(list @)`[6 3 1 ~] sub)
645 ! subtract-underflow
646 ! exit
648 > (roll `(list @)`[1 3 6 ~] sub)
649 q=4
650```
653---
654### `++scag`
656Prefix
658Accepts an atom `a` and `list` `b`, producing the first `a` elements of
659the front of the list.
661#### Accepts
663`a` is an atom.
665`b` is a list.
667#### Produces
669A list of the same type as `b`.
671#### Source
673```hoon
674 ++ scag :: prefix
675 ~/ %scag
676 |* [a=@ b=(list)]
677 |- ^+ b
678 ?: |(?=(~ b) =(0 a)) ~
679 [i.b $(b t.b, a (dec a))]
680```
682#### Examples
684```
685 > (scag 2 `(list @)`[1 2 3 4 ~])
686 [i=1 t=~[2]]
688 > (scag 10 `(list @)`[1 2 3 4 ~])
689 [i=1 t=~[2 3 4]]
690```
693---
694### `++skid`
696Separate
698Separates a `list` `a` into two lists - Those elements of `a` who produce
699true when slammed to gate `b` and those who produce `%.n`.
701(To "slam" means to call a gate and give it a sample/samples. In this instance,
702`a` is the list of samples that are given to the gate `b`.)
704#### Accepts
706`a` is a list.
708`b` is a gate that accepts one argument and produces a flag.
710#### Produces
712A cell of two lists.
714#### Source
716```hoon
717 ++ skid :: separate
718 ~/ %skid
719 |* [a=(list) b=$-(* ?)]
720 |- ^+ [p=a q=a]
721 ?~ a [~ ~]
722 =+ c=$(a t.a)
723 ?:((b i.a) [[i.a p.c] q.c] [p.c [i.a q.c]])
724```
727#### Examples
729```
730 > =a |=(a=@ (gth a 1))
731 > (skid `(list @)`[0 1 2 3 ~] a)
732 [p=[i=2 t=~[3]] q=[i=0 t=~[1]]]
733```
736---
737### `++skim`
739Suffix
741Cycles through the members of a list `a`, passing them to a gate `b` and
742producing a list of all of the members that produce `%.y`. Inverse of
743`skip`.
745#### Accepts
747`a` is a list.
749`b` is a gate that accepts one argument and produces a boolean.
751#### Produces
753A list.
755#### Source
757```hoon
758 ++ skim :: only
759 ~/ %skim
760 |* [a=(list) b=$-(* ?)]
761 |-
762 ^+ a
763 ?~ a ~
764 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
765```
767#### Examples
769```
770 > =a |=(a=@ (gth a 1))
771 > (skim `(list @)`[0 1 2 3 ~] a)
772 [i=2 t=~[3]]
773```
775---
776### `++skip`
778Except
780Cycles through the members of `list` `a`, passing them to a gate `b`.
781Produces a list of all of the members that produce `%.n`. Inverse of
782`skim`.
784#### Accepts
786`a` is a list.
788`b` is a gate that accepts one argument and produces a flag.
790#### Produces
792A list of the same type as `a`.
794#### Source
796```hoon
797 ++ skip :: except
798 ~/ %skip
799 |* [a=(list) b=$-(* ?)]
800 |-
801 ^+ a
802 ?~ a ~
803 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
804```
806#### Examples
808```
809 > =a |=(a=@ (gth a 1))
810 > (skip `(l)`[0 1 2 3 ~]) a)
811 [i=0 t=[i=1 t=~]]
812```
815---
816### `++slag`
818Suffix
820Accepts an atom `a` and list `b`, producing the remaining elements from
821`b` starting at `a`.
823#### Accepts
825`a` is an atom.
827`b` is a list.
829#### Produces
831A list of the same type as `b`.
833#### Source
835```hoon
836 ++ slag :: suffix
837 ~/ %slag
838 |* [a=@ b=(list)]
839 |- ^+ b
840 ?: =(0 a) b
841 ?~ b ~
842 $(b t.b, a (dec a))
843```
845#### Examples
847```
848 > (slag 2 (limo [1 2 3 4 ~]))
849 [i=3 t=[i=4 t=~]]
850 > (slag 1 (limo [1 2 3 4 ~]))
851 [i=2 t=[i=3 t=[i=4 t=~]]]
852```
855---
856### `++snag`
858Index
860Accepts an atom `a` and a `++list` `b`, producing the element at the index
861of `a`and failing if the list is null. Lists are 0-indexed.
863#### Accepts
865`a` is an atom.
867`b` is a list.
869#### Produces
871Produces an element of `b`, or crashes if no element exists at that index.
873#### Source
875```hoon
876 ++ snag :: index
877 ~/ %snag
878 |* [a=@ b=(list)]
879 |-
880 ?~ b
881 ~|('snag-fail' !!)
882 ?: =(0 a) i.b
883 $(b t.b, a (dec a))
884```
886#### Examples
888```
889 > (snag 2 "asdf")
890 ~~d
891 > (snag 0 `(list @ud)`~[1 2 3 4])
892 1
893```
896---
897### `++snoc`
899Append
901Accepts a `++list` `a` and a noun `b`, producing the list of `b` appended to `a`.
903#### Accepts
905`a` is a list.
907`b` is a noun.
909#### Produces
911Produces a list of `b` appended to `a`.
913#### Source
915```hoon
916 ++ snoc
917 |* [a/(list) b/*]
918 (weld a ^+(a [b]~))
919```
921#### Examples
923```
924 > `tape`(zing (snoc `(list tape)`~["a" "bc" "def"] "g"))
925 "abcdefg"
926 > (snoc `(list @ud)`~[1 2 3] 4)
927 ~[1 2 3 4]
928```
930---
931### `++snap`
933Replace item at index
935Accepts a `list` `a`, an atom `b`, and a noun `c`, producing the list of `a` with the item at index `b` replaced with `c`.
937#### Accepts
939`a` is a list.
941`b` is a atom.
943`c` is a noun.
946#### Produces
948the list of `a` with the item at index `b` replaced with `c`.
950#### Source
952```hoon
953 ++ snap
954 |* [a/(list) b/@ c/*]
955 ^+ a
956 (weld (scag b a) [c (slag +(b) a)])
957```
959#### Examples
961```
962 > (snap (limo ~[2 3 4]) 1 11)
963 ~[2 11 4]
964```
966---
967### `++into`
969Insert item at index
971Accepts a `list` `a`, an atom `b`, and a noun `c`, producing the list of `a` with the item `c` inserted at index `b`.
973#### Accepts
975`a` is a list.
977`b` is a atom.
979`c` is a noun.
982#### Produces
984the list of `a` with the item `c` inserted at index `b`.
986#### Source
988```hoon
989 ++ into
990 |* [a/(list) b/@ c/*]
991 ^+ a
992 (weld (scag b a) [c (slag b a)])
993```
995#### Examples
997```
998 > (into (limo ~[2 3 4]) 1 11)
999 ~[2 11 3 4]
1000```
1002---
1003### `++sort`
1005Quicksort
1007Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
1008produces a flag. `++sort` then produces a list of the elements of `a`,
1009sorted according to `b`.
1011#### Accepts
1013`a` is a list.
1015`b` is a gate that accepts two nouns and produces a boolean.
1017#### Produces
1019A list
1021#### Source
1023```hoon
1024 ++ sort !. :: quicksort
1025 ~/ %sort
1026 |* [a=(list) b=$-([* *] ?)]
1027 => .(a ^.(homo a))
1028 |- ^+ a
1029 ?~ a ~
1030 %+ weld
1031 $(a (skim t.a |=(c/_i.a (b c i.a))))
1032 ^+ t.a
1033 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
1034```
1036#### Examples
1038```
1039 > (sort `(list @)`[0 1 2 3 ~] gth)
1040 ~[3 2 1 0]
1041```
1044---
1045### `++spin`
1047Gate to list, with state
1049Accepts a `++list` `a`, some state `b`, and a gate `c`. `c` is called with
1050a tuple -- the head is an element of `a` and the tail is the state `b`, and
1051should produce a tuple of the transformed element and the (potentially
1052modified) state `b`. Produces a pair where the first element is a list of the
1053transformed elements of `a`, and the second element is the final value of `b`.
1055#### Accepts
1057`a` is a `++list`.
1059`b` is a noun.
1061`c` is a gate.
1063#### Produces
1065A pair of a list and a noun.
1067#### Source
1069```hoon
1070 ++ spin
1071 ~/ %spin
1072 |* [a=(list) b=* c=_|=(^ [** +<+])]
1073 => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
1074 =/ acc=(list _-:(c)) ~
1075 |- ^- (pair _acc _b)
1076 ?~ a
1077 [(flop acc) b]
1078 =^ res b (c i.a b)
1079 $(acc [res acc], a t.a)
1080```
1082#### Examples
1084```
1085 > %^ spin (limo ~[4 5 6]) :: Trivial example -- does nothing with the state
1087 |=([n=@ a=@] [n a])
1088 [p=~[4 5 6] q=0]
1090 > %^ spin (limo ~[4 5 6]) :: Form a pair with `p` as the index and `q` as the list element
1092 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1093 [p=~[[p=0 q=4] [p=1 q=5] [p=2 q=6]] q=3]
1095 > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
1096 ~(. og eny)
1097 |=([n=@ rng=_og] (rads:rng 10))
1098 [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>}>]
1099```
1101#### Discussion
1103`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
1104with entropy (`eny`). The head of the product is the random number, the tail
1105is the continuation of the RNG.
1109---
1110### `++spun`
1112Gate to list, with state
1114Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
1115derived by **bunting** the tail of the sample of gate `b`, instead of
1116being passed in explicitly as in `++spin`. Produces a list with the
1117gate applied to each element of the original list. `b` is called with a tuple --
1118the head is an element of `a` and the tail is the state `c`, and should
1119produce a tuple of the transformed element and the (potentially modified)
1120state `c`.
1122#### Accepts
1124`a` is a `++list`.
1126`b` is a gate.
1128#### Produces
1130A list.
1132#### Source
1134```hoon
1135 ++ spun
1136 ~/ %spun
1137 |* [a=(list) b=_|=(^ [** +<+])]
1138 p:(spin a +<+.b b)
1139```
1141#### Examples
1143```
1144 > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
1145 |=([n=@ a=@] [`(pair)`[a n] +(a)])
1146 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1148 > =l (limo ~[7 8 9])
1149 > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
1150 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1151 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1152```
1155---
1156### `++swag`
1158Infix
1160Similar to `substr` in Javascript: extracts a string infix, beginning at
1161inclusive index `a`, producing `b` number of characters.
1163#### Accepts
1165`a` is an atom.
1167`b` is an atom.
1169`c` is a list.
1171#### Produces
1173A list of the same type as `c`.
1175#### Source
1177```hoon
1178 ++ swag
1179 |* [[a=@ b=@] c=(list)]
1180 (scag +<-> (slag +<-< c))
1181```
1183#### Examples
1185```
1186 > (swag [2 5] "roly poly")
1187 "ly po"
1189 > (swag [2 2] (limo [1 2 3 4 ~]))
1190 [i=3 t=[i=4 t=~]]
1191```
1194---
1195### `++turn`
1197Gate to list
1199Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
1200to each element of the original list.
1202#### Accepts
1204`a` is a list.
1206`b` is a gate.
1208#### Produces
1210A list.
1212#### Source
1214```hoon
1215 ++ turn
1216 ~/ %turn
1217 |* [a=(list) b=gate]
1218 |-
1219 ?~ a ~
1220 [i=(b i.a) t=$(a t.a)]
1221```
1223#### Examples
1225```
1226 > (turn (limo [104 111 111 110 ~]) @t)
1227 <|h o o n|>
1229 > =a |=(a=@ (add a 4))
1230 > (turn (limo [1 2 3 4 ~]) a)
1231 ~[5 6 7 8]
1232```
1234#### Discussion
1236`turn` is Hoon's version of 'map' in Haskell.
1238---
1239### `++weld`
1241Concatenate
1243Concatenate two `++list`s `a` and `b`.
1245#### Accepts
1247`a` and `b` are lists.
1249#### Source
1251```hoon
1252 ++ weld
1253 ~/ %weld
1254 |* [a=(list) b=(list)]
1255 => .(a ^.(homo a), b ^.(homo b))
1256 |- ^+ b
1257 ?~ a b
1258 [i.a $(a t.a)]
1259```
1261#### Examples
1263```
1264 > (weld "urb" "it")
1265 "urbit"
1267 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1268 ~[1 2 3 4]
1269```
1272---
1273### `++welp`
1275Perfect weld
1277Concatenate two `++list`s `a` and `b` without losing their type information
1278to homogenization.
1280#### Accepts
1282`a` is a list.
1284`b` is a list.
1286#### Produces
1288A list.
1290#### Source
1292```hoon
1293 ++ welp
1294 =| [* *]
1295 |%
1296 +- $
1297 ?~ +<-
1298 +<-(. +<+)
1299 +<-(+ $(+<- +<->))
1300 --
1301```
1303#### Examples
1305```
1306 > (welp "foo" "bar")
1307 "foobar"
1309 > (welp ~[60 61 62] ~[%a %b %c])
1310 [60 61 62 %a %b %c ~]
1312 > ? (welp ~[60 61 62] ~[%a %b %c])
1313 {@ud @ud @ud $a $b $c $~}
1314 [60 61 62 %a %b %c ~]
1316 > (welp [sa+1 so+2 ~] si=3)
1317 [[%sa 1] [%so 2] si=3]
1318```
1321---
1322### `++zing`
1324Turns a `++list` of lists into a single list by promoting the elements of
1325each sublist into the higher.
1327#### Accepts
1329A list of lists.
1331#### Produces
1333A list.
1335#### Source
1337```hoon
1338 ++ zing
1339 =| *
1340 |%
1341 +- $
1342 ?~ +<
1343 +<
1344 (welp +<- $(+< +<+))
1345 --
1346```
1349#### Examples
1351```
1352 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1353 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1355 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1356 ~[1 97 2 98 3 99 4 100]
1357```
1359---