on master help sign in
Update 2d
24caed4rmariani
docs/hoon/library/2b.md+48−39
@@ -8,8 +8,8 @@ navhome: /docs/
8
8
9All indices in `list`
9All indices in `list`
10
10
11−Produces the indices of all occurrences of `list` `nedl` in
11+Produces the indices of all occurrences of `nedl` in `hstk` as a `list` of
12−`list` `hstk` as a `list` of atoms.
12+atoms.
13
13
14#### Accepts
14#### Accepts
15
15
@@ -23,7 +23,7 @@ A `list`.
23
23
24#### Source
24#### Source
25
25
26− ++ fand :: all indices
26+ ++ fand
27 ~/ %fand
27 ~/ %fand
28 |= [nedl=(list) hstk=(list)]
28 |= [nedl=(list) hstk=(list)]
29 =| i=@ud
29 =| i=@ud
@@ -42,13 +42,13 @@ A `list`.
42
42
43#### Examples
43#### Examples
44
44
45− > (fand [3]~ ~[1 2 3])
45+ > (fand ~[3] ~[1 2 3])
46 ~[2]
46 ~[2]
47
47
48− > (fand [4]~ ~[1 2 3])
48+ > (fand ~[4] ~[1 2 3])
49 ~
49 ~
50
50
51− > (fand ['a']~ "cbabab")
51+ > (fand ~['a'] "cbabab")
52 ~[2 4]
52 ~[2 4]
53
53
54 > (fand "ba" "cbabab")
54 > (fand "ba" "cbabab")
@@ -61,8 +61,8 @@ A `list`.
61
61
62First index in `list`
62First index in `list`
63
63
64−Produces the index of the first occurrence of `list` `nedl` in
64+Produces the index of the first occurrence of `nedl` in `hstk` as the `unit`
65−`list` `hstk` as the `unit` of an atom.
65+of an atom.
66
66
67#### Accepts
67#### Accepts
68
68
@@ -76,7 +76,7 @@ The `unit` of an atom.
76
76
77#### Source
77#### Source
78
78
79− ++ find :: first index
79+ ++ find
80 ~/ %find
80 ~/ %find
81 |= [nedl=(list) hstk=(list)]
81 |= [nedl=(list) hstk=(list)]
82 =| i=@ud
82 =| i=@ud
@@ -127,7 +127,7 @@ A `list`.
127
127
128#### Source
128#### Source
129
129
130− ++ flop :: reverse
130+ ++ flop
131 ~/ %flop
131 ~/ %flop
132 |* a=(list)
132 |* a=(list)
133 => .(a (homo a))
133 => .(a (homo a))
@@ -168,7 +168,7 @@ a `list`.
168
168
169#### Source
169#### Source
170
170
171− ++ gulf :: range inclusive
171+ ++ gulf
172 |= [a=@ b=@]
172 |= [a=@ b=@]
173 ^- (list @)
173 ^- (list @)
174 ?:(=(a +(b)) ~ [a $(a +(a))])
174 ?:(=(a +(b)) ~ [a $(a +(a))])
@@ -187,7 +187,8 @@ a `list`.
187Homogenize
187Homogenize
188
188
189Produces a `list` whose type is a fork of all the contained types in the
189Produces a `list` whose type is a fork of all the contained types in the
190−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
191+ same.
191
192
192#### Accepts
193#### Accepts
193
194
@@ -199,7 +200,7 @@ a `list`.
199
200
200#### Source
201#### Source
201
202
202− ++ homo :: homogenize
203+ ++ homo
203 |* a=(list)
204 |* a=(list)
204 ^+ =< $
205 ^+ =< $
205 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
206 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
@@ -211,11 +212,14 @@ a `list`.
211
212
212 > lyst
213 > lyst
213 [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=~]]]]]
215+
214 > (homo lyst)
216 > (homo lyst)
215 ~[1 97 2 98 [~ u=10]]
217 ~[1 97 2 98 [~ u=10]]
218+
216 > =a (limo [1 2 3 ~])
219 > =a (limo [1 2 3 ~])
217 > a
220 > a
218 [i=1 t=[i=2 t=[i=3 t=~]]]
221 [i=1 t=[i=2 t=[i=3 t=~]]]
222+
219 > (homo a)
223 > (homo a)
220 ~[1 2 3]
224 ~[1 2 3]
221
225
@@ -238,7 +242,7 @@ an atom.
238
242
239#### Source
243#### Source
240
244
241− ++ lent :: length
245+ ++ lent
242 ~/ %lent
246 ~/ %lent
243 |= a=(list)
247 |= a=(list)
244 ^- @
248 ^- @
@@ -314,7 +318,7 @@ every element of `++list` `a`.
314
318
315#### Source
319#### Source
316
320
317− ++ lien :: some of
321+ ++ lien
318 ~/ %lien
322 ~/ %lien
319 |* [a=(list) b=$-(* ?)]
323 |* [a=(list) b=$-(* ?)]
320 |- ^- ?
324 |- ^- ?
@@ -327,6 +331,7 @@ every element of `++list` `a`.
327 > =a |=(a=@ (gte a 1))
331 > =a |=(a=@ (gte a 1))
328 > (lien `(list @)`[0 1 2 1 ~] a)
332 > (lien `(list @)`[0 1 2 1 ~] a)
329 %.y
333 %.y
334+
330 > =a |=(a=@ (gte a 3))
335 > =a |=(a=@ (gte a 3))
331 > (lien `(list @)`[0 1 2 1 ~]) a)
336 > (lien `(list @)`[0 1 2 1 ~]) a)
332 %.n
337 %.n
@@ -862,13 +867,15 @@ A list.
862#### Source
867#### Source
863
868
864 ++ spin
869 ++ spin
870+ ~/ %spin
865− |* [a=(list) b=_|=([* *] [** +<+]) c/*]
871+ |* [a=(list) b=* c=_|=(^ [** +<+])]
866− :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
872+ => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
867− |-
873+ =/ acc=(list _-:(c)) ~
874+ |- ^- (pair _acc _b)
868 ?~ a
875 ?~ a
869− ~
876+ [(flop acc) b]
870− =+ v=(b i.a c)
877+ =^ res b (c i.a b)
871− [i=-.v t=$(a t.a, c +.v)]
878+ $(acc [res acc], a t.a)
872
879
873
880
874#### Examples
881#### Examples
@@ -885,7 +892,7 @@ A list.
885 ~[[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]]
886
893
887 > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
894 > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
888− |=([n=@ rng=_og] (rads:rng 10))
895+ |=([n=@ rng=_og] (rads:rng 10))
889 ~(. og eny)
896 ~(. og eny)
890 ~[5 5 9 4 1 7 9 9 9 6]
897 ~[5 5 9 4 1 7 9 9 9 6]
891
898
@@ -905,7 +912,8 @@ Gate to list, with state
905Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
912Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
906derived 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
907being passed in explicitly as in `++spin`. Produces a list with the
914being passed in explicitly as in `++spin`. Produces a list with the
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
915+gate applied to each element of the original list. `b` is called with a tuple --
916+ the head is an element of `a` and the tail is the state `c`, and should
909produce a tuple of the transformed element and the (potentially modified)
917produce a tuple of the transformed element and the (potentially modified)
910state `c`.
918state `c`.
911
919
@@ -922,23 +930,19 @@ A list.
922#### Source
930#### Source
923
931
924 ++ spun
932 ++ spun
933+ ~/ %spun
925− |* [a=(list) b=_|=([* *] [** +<+])]
934+ |* [a=(list) b=_|=(^ [** +<+])]
926− =| c/_+<+.b
935+ p:(spin a +<+.b b)
927− |-
928− ?~ a
929− ~
930− =+ v=(b i.a c)
931− [i=-.v t=$(a t.a, c +.v)]
932
936
933
937
934#### Examples
938#### Examples
935
939
936− > %+ spun (limo ~[4 5 6]) ::`p` as the index and `q` as the list element
940+ > %+ spun (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
937 |=([n=@ a=@] [`(pair)`[a n] +(a)])
941 |=([n=@ a=@] [`(pair)`[a n] +(a)])
938 ~[[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]]
939
943
944+ > =l (limo ~[7 8 9])
940− > =l (limo ~[7 8 9]) ::joins two lists into a list of pairs
945+ > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
941− > %+ spun (limo ~[4 5 6])
942 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
946 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
943 ~[[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]]
944
948
@@ -971,6 +975,7 @@ A list of the same type as `c`.
971
975
972 > (swag [2 5] "roly poly")
976 > (swag [2 5] "roly poly")
973 "ly po"
977 "ly po"
978+
974 > (swag [2 2] (limo [1 2 3 4 ~]))
979 > (swag [2 2] (limo [1 2 3 4 ~]))
975 [i=3 t=[i=4 t=~]]
980 [i=3 t=[i=4 t=~]]
976
981
@@ -1039,6 +1044,7 @@ Concatenate two `++list`s `a` and `b`.
1039
1044
1040 > (weld "urb" "it")
1045 > (weld "urb" "it")
1041 ~[~~u ~~r ~~b ~~i ~~t]
1046 ~[~~u ~~r ~~b ~~i ~~t]
1047+
1042 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1048 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
1043 ~[1 2 3 4]
1049 ~[1 2 3 4]
1044
1050
@@ -1078,13 +1084,16 @@ A list.
1078
1084
1079 > (welp "foo" "bar")
1085 > (welp "foo" "bar")
1080 "foobar"
1086 "foobar"
1087+
1081− ~zod/arvo=/hoon/hoon> (welp ~[60 61 62] ~[%a %b %c])
1088+ > (welp ~[60 61 62] ~[%a %b %c])
1082 [60 61 62 %a %b %c ~]
1089 [60 61 62 %a %b %c ~]
1090+
1083− ~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 $~}
1084 [60 61 62 %a %b %c ~]
1093 [60 61 62 %a %b %c ~]
1085− [@ud @ud @ud %a %b %c %~]
1094+
1086− ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si=3)
1095+ > (welp [sa+1 so+2 ~] si=3)
1087− [[%sa 1] [%so 2] %si 3]
1096+ [[%sa 1] [%so 2] si=3]
1088
1097
1089
1098
1090
1099
@@ -1121,7 +1130,7 @@ A list.
1121
1130
1122 > (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' ~]) ~]))
1123 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1132 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1124−
1133+
1125 > (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' ~]) ~]))
1126 ~[1 97 2 98 3 99 4 100]
1135 ~[1 97 2 98 3 99 4 100]
1127
1136