on master help sign in
Update 2d

Fixed examples and unnecessary used of `list`

commit24caed4bab7a287d5359f4a84e9012df01a89def authorrmariani <robert@tlon.io> dateMon 4 Jun 2018, 15:51 (8 years ago) parentafd003c
1 file changed+48−39
docs/hoon/library/2b.md+48−39
docs/hoon/library/2b.md+48−39
@@ -8,8 +8,8 @@ navhome: /docs/
88
99All indices in `list`
1010
11−Produces the indices of all occurrences of `list` `nedl` in
12−`list` `hstk` as a `list` of atoms.
11+Produces the indices of all occurrences of `nedl` in `hstk` as a `list` of
12+atoms.
1313
1414#### Accepts
1515
@@ -23,7 +23,7 @@ A `list`.
2323
2424#### Source
2525
26− ++ fand :: all indices
26+ ++ fand
2727 ~/ %fand
2828 |= [nedl=(list) hstk=(list)]
2929 =| i=@ud
@@ -42,13 +42,13 @@ A `list`.
4242
4343#### Examples
4444
45− > (fand [3]~ ~[1 2 3])
45+ > (fand ~[3] ~[1 2 3])
4646 ~[2]
4747
48− > (fand [4]~ ~[1 2 3])
48+ > (fand ~[4] ~[1 2 3])
4949 ~
5050
51− > (fand ['a']~ "cbabab")
51+ > (fand ~['a'] "cbabab")
5252 ~[2 4]
5353
5454 > (fand "ba" "cbabab")
@@ -61,8 +61,8 @@ A `list`.
6161
6262First index in `list`
6363
64−Produces the index of the first occurrence of `list` `nedl` in
65−`list` `hstk` as the `unit` of an atom.
64+Produces the index of the first occurrence of `nedl` in `hstk` as the `unit`
65+of an atom.
6666
6767#### Accepts
6868
@@ -76,7 +76,7 @@ The `unit` of an atom.
7676
7777#### Source
7878
79− ++ find :: first index
79+ ++ find
8080 ~/ %find
8181 |= [nedl=(list) hstk=(list)]
8282 =| i=@ud
@@ -127,7 +127,7 @@ A `list`.
127127
128128#### Source
129129
130− ++ flop :: reverse
130+ ++ flop
131131 ~/ %flop
132132 |* a=(list)
133133 => .(a (homo a))
@@ -168,7 +168,7 @@ a `list`.
168168
169169#### Source
170170
171− ++ gulf :: range inclusive
171+ ++ gulf
172172 |= [a=@ b=@]
173173 ^- (list @)
174174 ?:(=(a +(b)) ~ [a $(a +(a))])
@@ -187,7 +187,8 @@ a `list`.
187187Homogenize
188188
189189Produces 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.
191192
192193#### Accepts
193194
@@ -199,7 +200,7 @@ a `list`.
199200
200201#### Source
201202
202− ++ homo :: homogenize
203+ ++ homo
203204 |* a=(list)
204205 ^+ =< $
205206 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
@@ -211,11 +212,14 @@ a `list`.
211212
212213 > lyst
213214 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
215+
214216 > (homo lyst)
215217 ~[1 97 2 98 [~ u=10]]
218+
216219 > =a (limo [1 2 3 ~])
217220 > a
218221 [i=1 t=[i=2 t=[i=3 t=~]]]
222+
219223 > (homo a)
220224 ~[1 2 3]
221225
@@ -238,7 +242,7 @@ an atom.
238242
239243#### Source
240244
241− ++ lent :: length
245+ ++ lent
242246 ~/ %lent
243247 |= a=(list)
244248 ^- @
@@ -314,7 +318,7 @@ every element of `++list` `a`.
314318
315319#### Source
316320
317− ++ lien :: some of
321+ ++ lien
318322 ~/ %lien
319323 |* [a=(list) b=$-(* ?)]
320324 |- ^- ?
@@ -327,6 +331,7 @@ every element of `++list` `a`.
327331 > =a |=(a=@ (gte a 1))
328332 > (lien `(list @)`[0 1 2 1 ~] a)
329333 %.y
334+
330335 > =a |=(a=@ (gte a 3))
331336 > (lien `(list @)`[0 1 2 1 ~]) a)
332337 %.n
@@ -862,13 +867,15 @@ A list.
862867#### Source
863868
864869 ++ spin
865− |* [a=(list) b=_|=([* *] [** +<+]) c/*]
866− :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
867− |-
870+ ~/ %spin
871+ |* [a=(list) b=* c=_|=(^ [** +<+])]
872+ => .(c `$-([_?>(?=(^ a) i.a) _b] [_-:(c) _b])`c)
873+ =/ acc=(list _-:(c)) ~
874+ |- ^- (pair _acc _b)
868875 ?~ a
869− ~
870− =+ v=(b i.a c)
871− [i=-.v t=$(a t.a, c +.v)]
876+ [(flop acc) b]
877+ =^ res b (c i.a b)
878+ $(acc [res acc], a t.a)
872879
873880
874881#### Examples
@@ -885,7 +892,7 @@ A list.
885892 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
886893
887894 > %^ 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))
889896 ~(. og eny)
890897 ~[5 5 9 4 1 7 9 9 9 6]
891898
@@ -905,7 +912,8 @@ Gate to list, with state
905912Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
906913derived by *bunting* the tail of the sample of gate `b`, instead of
907914being 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
909917produce a tuple of the transformed element and the (potentially modified)
910918state `c`.
911919
@@ -922,23 +930,19 @@ A list.
922930#### Source
923931
924932 ++ spun
925− |* [a=(list) b=_|=([* *] [** +<+])]
926− =| c/_+<+.b
927− |-
928− ?~ a
929− ~
930− =+ v=(b i.a c)
931− [i=-.v t=$(a t.a, c +.v)]
933+ ~/ %spun
934+ |* [a=(list) b=_|=(^ [** +<+])]
935+ p:(spin a +<+.b b)
932936
933937
934938#### Examples
935939
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
937941 |=([n=@ a=@] [`(pair)`[a n] +(a)])
938942 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
939943
940− > =l (limo ~[7 8 9]) ::joins two lists into a list of pairs
941− > %+ spun (limo ~[4 5 6])
944+ > =l (limo ~[7 8 9])
945+ > %+ spun (limo ~[4 5 6]) :: joins two lists into a list of pairs
942946 |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
943947 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
944948
@@ -971,6 +975,7 @@ A list of the same type as `c`.
971975
972976 > (swag [2 5] "roly poly")
973977 "ly po"
978+
974979 > (swag [2 2] (limo [1 2 3 4 ~]))
975980 [i=3 t=[i=4 t=~]]
976981
@@ -1039,6 +1044,7 @@ Concatenate two `++list`s `a` and `b`.
10391044
10401045 > (weld "urb" "it")
10411046 ~[~~u ~~r ~~b ~~i ~~t]
1047+
10421048 > (weld (limo [1 2 ~]) (limo [3 4 ~]))
10431049 ~[1 2 3 4]
10441050
@@ -1078,13 +1084,16 @@ A list.
10781084
10791085 > (welp "foo" "bar")
10801086 "foobar"
1081− ~zod/arvo=/hoon/hoon> (welp ~[60 61 62] ~[%a %b %c])
1087+
1088+ > (welp ~[60 61 62] ~[%a %b %c])
10821089 [60 61 62 %a %b %c ~]
1083− ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1090+
1091+ > ? (welp ~[60 61 62] ~[%a %b %c])
1092+ {@ud @ud @ud $a $b $c $~}
10841093 [60 61 62 %a %b %c ~]
1085− [@ud @ud @ud %a %b %c %~]
1086− ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si=3)
1087− [[%sa 1] [%so 2] %si 3]
1094+
1095+ > (welp [sa+1 so+2 ~] si=3)
1096+ [[%sa 1] [%so 2] si=3]
10881097
10891098
10901099
@@ -1121,7 +1130,7 @@ A list.
11211130
11221131 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
11231132 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1124−
1133+
11251134 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
11261135 ~[1 97 2 98 3 99 4 100]
11271136