on master help sign in
Update 2b
afd003crmariani
docs/hoon/library/2b.md+426−465
@@ -4,28 +4,132 @@ navhome: /docs/
4
4
5
5
6# 2b: list logic
6# 2b: list logic
7−Reverse
7+### `++fand`
8+
9+All indices in `list`
10+
11+Produces the indices of all occurrences of `list` `nedl` in
12+`list` `hstk` as a `list` of atoms.
13+
14+#### Accepts
15+
16+`nedl` is a list.
17+
18+`hstk` is a list.
19+
20+#### Produces
21+
22+A `list`.
23+
24+#### Source
25+
26+ ++ fand :: all indices
27+ ~/ %fand
28+ |= [nedl=(list) hstk=(list)]
29+ =| i=@ud
30+ =| fnd=(list @ud)
31+ |- ^+ fnd
32+ =+ [n=nedl h=hstk]
33+ |-
34+ ?: |(?=($~ n) ?=($~ h))
35+ (flop fnd)
36+ ?: =(i.n i.h)
37+ ?~ t.n
38+ ^$(i +(i), hstk +.hstk, fnd [i fnd])
39+ $(n t.n, h t.h)
40+ ^$(i +(i), hstk +.hstk)
41+
42+
43+#### Examples
44+
45+ > (fand [3]~ ~[1 2 3])
46+ ~[2]
47+
48+ > (fand [4]~ ~[1 2 3])
49+ ~
50+
51+ > (fand ['a']~ "cbabab")
52+ ~[2 4]
53+
54+ > (fand "ba" "cbabab")
55+ ~[1 3]
56+
57+
58+
59+***
60+### `++find`
61+
62+First index in `list`
63+
64+Produces the index of the first occurrence of `list` `nedl` in
65+`list` `hstk` as the `unit` of an atom.
66+
67+#### Accepts
68+
69+`nedl` is a list.
70+
71+`hstk` is a list.
72+
73+#### Produces
74+
75+The `unit` of an atom.
76+
77+#### Source
78+
79+ ++ find :: first index
80+ ~/ %find
81+ |= [nedl=(list) hstk=(list)]
82+ =| i=@ud
83+ |- ^- (unit @ud)
84+ =+ [n=nedl h=hstk]
85+ |-
86+ ?: |(?=($~ n) ?=($~ h))
87+ ~
88+ ?: =(i.n i.h)
89+ ?~ t.n
90+ `i
91+ $(n t.n, h t.h)
92+ ^$(i +(i), hstk +.hstk)
93+
94+
95+#### Examples
96+
97+ > (find [3]~ ~[1 2 3])
98+ [~ u=2]
99+
100+ > (find [4]~ ~[1 2 3])
101+ ~
102+
103+ > (find ['c']~ "cbabab")
104+ [~ u=0]
105+
106+ > (find "ab" "cbabab")
107+ [~ u=1]
8
108
109+ > (find "bab" "cbabab")
110+ [~ u=2]
111+
112+
113+***
9### `++flop`
114### `++flop`
10
115
11−Produces the list `a` in reverse order.
116+Reverse
12
117
13−Accepts
118+Produces the `list` `a` in reverse order.
14−-------
15
119
16−`a` is a list.
120+#### Accepts
17
121
18−Produces
122+`a` is a `list`.
19−--------
20
123
124+#### Produces
125+
21−A list.
126+A `list`.
22
127
23−Source
128+#### Source
24−------
25
129
26 ++ flop :: reverse
130 ++ flop :: reverse
27 ~/ %flop
131 ~/ %flop
28− |* a/(list)
132+ |* a=(list)
29 => .(a (homo a))
133 => .(a (homo a))
30 ^+ a
134 ^+ a
31 =+ b=`_a`~
135 =+ b=`_a`~
@@ -35,46 +139,75 @@ Source
35
139
36
140
37
141
38−Examples
142+#### Examples
39−--------
40
143
41− > =a (limo [1 2 3 ~])
144+ > =a [1 2 3 ~]
42 > (flop a)
145 > (flop a)
43 ~[3 2 1]
146 ~[3 2 1]
44
147
148+ > (flop (flop a))
149+ ~[1 2 3]
150+
151+***
152+### `++gulf`
153+
154+List from range
155+
156+Produces a `list` composed of each consecutive integer starting from `a` and
157+ending with `b`. `a` and `b` are themselves included.
158+
159+#### Accepts
160+
161+`a` is an atom.
45
162
163+`b` is an atom.
164+
165+#### Produces
166+
167+a `list`.
168+
169+#### Source
170+
171+ ++ gulf :: range inclusive
172+ |= [a=@ b=@]
173+ ^- (list @)
174+ ?:(=(a +(b)) ~ [a $(a +(a))])
175+
176+#### Examples
177+
178+ > (gulf 1 6)
179+ ~[1 2 3 4 5 6]
180+
181+ > `(list @t)`(gulf 99 106)
182+ <|c d e f g h i j|>
46
183
47***
184***
48### `++homo`
185### `++homo`
49
186
50Homogenize
187Homogenize
51
188
52−Produces a `++list` whose type is a fork of all the contained types in the
189+Produces a `list` whose type is a fork of all the contained types in the
53list `a`. Used when you want to make all the types of the elements of a list the same.
190list `a`. Used when you want to make all the types of the elements of a list the same.
54
191
55−Accepts
192+#### Accepts
56−-------
57
193
58−`a` is a list.
194+`a` is a `list`.
59
195
60−Produces
196+#### Produces
61−--------
62
197
63−a list.
198+a `list`.
64
199
65−Source
200+#### Source
66−------
67
201
68 ++ homo :: homogenize
202 ++ homo :: homogenize
69− |* a/(list)
203+ |* a=(list)
70 ^+ =< $
204 ^+ =< $
71 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
205 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
72 --
206 --
73 a
207 a
74
208
75
209
76−Examples
210+#### Examples
77−--------
78
211
79 > lyst
212 > lyst
80 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
213 [i=1 t=[i=97 t=[i=2 t=[i=98 t=[i=[~ u=10] t=~]]]]]
@@ -93,24 +226,21 @@ Examples
93
226
94List length
227List length
95
228
96−Produces the length of any `++list` `a` as an atom.
229+Produces the length of any `list` `a` as an atom.
97
230
98−Accepts
231+#### Accepts
99−-------
100
232
101−`a` is a list.
233+`a` is a `list`.
102
234
103−Produces
235+#### Produces
104−--------
105
236
106an atom.
237an atom.
107
238
108−Source
239+#### Source
109−------
110
240
111 ++ lent :: length
241 ++ lent :: length
112 ~/ %lent
242 ~/ %lent
113− |= a/(list)
243+ |= a=(list)
114 ^- @
244 ^- @
115 =+ b=0
245 =+ b=0
116 |-
246 |-
@@ -118,120 +248,13 @@ Source
118 $(a t.a, b +(b))
248 $(a t.a, b +(b))
119
249
120
250
121−Examples
251+#### Examples
122−--------
123
252
124− > (lent (limo [1 2 3 4 ~]))
253+ > (lent [1 2 3 4 ~]))
125 4
254 4
126− > (lent (limo [1 'a' 2 'b' (some 10) ~]))
127− 5
128−
129−
130−
131−***
132−### `++find`
133−
134−First index in list
135−
136−Produces the index of the first occurrence of `++list` `nedl` in
137−`++list` `hstk` as the `++unit` of an atom.
138−
139−Accepts
140−-------
141−
142−`nedl` is a list.
143−
144−`hstk` is a list.
145−
146−Produces
147−--------
148−
149−The `++unit` of an atom.
150−
151−Source
152−------
153−
154− ++ find :: first index
155− ~/ %find
156− |= {nedl/(list) hstk/(list)}
157− =| i/@ud
158− |- ^- (unit @ud)
159− =+ [n=nedl h=hstk]
160− |-
161− ?: |(?=($~ n) ?=($~ h))
162− ~
163− ?: =(i.n i.h)
164− ?~ t.n
165− `i
166− $(n t.n, h t.h)
167− ^$(i +(i), hstk +.hstk)
168−
169−
170−Examples
171−--------
172−
173− > (find [3]~ ~[1 2 3])
174− [~ 2]
175− > (find [4]~ ~[1 2 3])
176− ~
177− > (find ['a']~ "cbabab")
178− [~ 2]
179− > (find "ab" "cbabab")
180− [~ 2]
181−
182−
183−
184−***
185−### `++fand`
186
255
187−All indices in list
256+ > (lent [1 'a' 2 'b' (some 10) ~])
188−
257+ 5
189−Produces the indices of all occurrences of `++list` `nedl` in
190−`++list` `hstk` as a `++list` of atoms.
191−
192−Accepts
193−-------
194−
195−`nedl` is a list.
196−
197−`hstk` is a list.
198−
199−Produces
200−--------
201−
202−A `++list` of atoms.
203−
204−Source
205−------
206−
207− ++ fand :: all indices
208− ~/ %fand
209− |= {nedl/(list) hstk/(list)}
210− =| i/@ud
211− =| fnd/(list @ud)
212− |- ^+ fnd
213− =+ [n=nedl h=hstk]
214− |-
215− ?: |(?=($~ n) ?=($~ h))
216− (flop fnd)
217− ?: =(i.n i.h)
218− ?~ t.n
219− ^$(i +(i), hstk +.hstk, fnd [i fnd])
220− $(n t.n, h t.h)
221− ^$(i +(i), hstk +.hstk)
222−
223−
224−Examples
225−--------
226−
227− > (fand [3]~ ~[1 2 3])
228− ~[2]
229− > (fand [4]~ ~[1 2 3])
230− ~
231− > (fand ['a']~ "cbabab")
232− ~[2 4]
233− > (fand "ab" "cbabab")
234− ~[2 4]
235
258
236
259
237
260
@@ -240,40 +263,37 @@ Examples
240
263
241Logical "and" on list
264Logical "and" on list
242
265
243−Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `++list` `a`.
266+Computes the Boolean logical "and" on the results of gate `b` applied to each individual element in `list` `a`.
244
267
245−Accepts
268+#### Accepts
246−-------
247
269
248`a` is a list.
270`a` is a list.
249
271
250`b` is a gate.
272`b` is a gate.
251
273
252−Produces
274+#### Produces
253−--------
254
275
255A boolean.
276A boolean.
256
277
257−Source
278+#### Source
258−------
259
279
260 ++ levy
280 ++ levy
261 ~/ %levy :: all of
281 ~/ %levy :: all of
262− |* {a/(list) b/$-(* ?)}
282+ |* [a=(list) b=$-(* ?)]
263 |- ^- ?
283 |- ^- ?
264 ?~ a &
284 ?~ a &
265 ?. (b i.a) |
285 ?. (b i.a) |
266 $(a t.a)
286 $(a t.a)
267
287
268
288
269−Examples
289+#### Examples
270−--------
271
290
272− > =a |=(a/@ (lte a 1))
291+ > =a |=(a=@ (lte a 1))
273− > (levy (limo [0 1 2 1 ~]) a)
292+ > (levy `(list @)`[0 1 2 1 ~] a)
274 %.n
293 %.n
294+
275− > =a |=(a/@ (lte a 3))
295+ > =a |=(a=@ (lte a 3))
276− > (levy (limo [0 1 2 1 ~]) a)
296+ > (levy `(list @)`[0 1 2 1 ~] a)
277 %.y
297 %.y
278
298
279
299
@@ -283,34 +303,32 @@ Examples
283
303
284Logical "or" on list
304Logical "or" on list
285
305
286−Computes the Boolean logical "or" on the results of applying [gate]() `b` to every element of [`++list`]() `a`.
306+Computes the Boolean logical "or" on the results of applying `gate` `b` to
307+every element of `++list` `a`.
287
308
288−Accepts
309+#### Accepts
289−-------
290
310
291`a` is a list.
311`a` is a list.
292
312
293`b` is a gate.
313`b` is a gate.
294
314
295−Source
315+#### Source
296−------
297
316
298 ++ lien :: some of
317 ++ lien :: some of
299 ~/ %lien
318 ~/ %lien
300− |* {a/(list) b/$-(* ?)}
319+ |* [a=(list) b=$-(* ?)]
301 |- ^- ?
320 |- ^- ?
302 ?~ a |
321 ?~ a |
303 ?: (b i.a) &
322 ?: (b i.a) &
304 $(a t.a)
323 $(a t.a)
305−
324+
306−Examples
325+#### Examples
307−--------
308
326
309 > =a |=(a=@ (gte a 1))
327 > =a |=(a=@ (gte a 1))
310− > (lien (limo [0 1 2 1 ~]) a)
328+ > (lien `(list @)`[0 1 2 1 ~] a)
311 %.y
329 %.y
312 > =a |=(a=@ (gte a 3))
330 > =a |=(a=@ (gte a 3))
313− > (lien (limo [0 1 2 1 ~]) a)
331+ > (lien `(list @)`[0 1 2 1 ~]) a)
314 %.n
332 %.n
315
333
316
334
@@ -320,20 +338,17 @@ Examples
320
338
321List Constructor
339List Constructor
322
340
323−Turns a null-terminated tuple into a [`++list`]().
341+Turns a null-terminated tuple into a `list`.
324
342
325−Accepts
343+#### Accepts
326−-------
327
344
328`a` is a null-terminated tuple.
345`a` is a null-terminated tuple.
329
346
330−Produces
347+#### Produces
331−--------
332
348
333A `++list`.
349A `++list`.
334
350
335−Source
351+#### Source
336−------
337
352
338 ++ limo :: listify
353 ++ limo :: listify
339 |* a=*
354 |* a=*
@@ -342,8 +357,7 @@ Source
342 --
357 --
343 a
358 a
344
359
345−Examples
360+#### Examples
346−--------
347
361
348 > (limo [1 2 3 ~])
362 > (limo [1 2 3 ~])
349 [i=1 t=[i=2 t=[i=3 t=~]]]
363 [i=1 t=[i=2 t=[i=3 t=~]]]
@@ -355,28 +369,25 @@ Examples
355
369
356Maybe transform
370Maybe transform
357
371
358−Passes each member of `++list` `a` to gate `b`, which must produce a
372+Passes each member of `list` `a` to gate `b`, which must produce a
359−`++unit`. Produces a new list with all the results that do not produce
373+`unit`. Produces a new list with all the results that do not produce
360`~`.
374`~`.
361
375
362−Accepts
376+#### Accepts
363−-------
364
377
365`a` is a list.
378`a` is a list.
366
379
367`b` is a gate that produces a unit.
380`b` is a gate that produces a unit.
368
381
369−Produces
382+#### Produces
370−--------
371
383
372A unit.
384A unit.
373
385
374−Source
386+#### Source
375−------
376
387
377 ++ murn :: maybe transform
388 ++ murn :: maybe transform
378 ~/ %murn
389 ~/ %murn
379− |* {a/(list) b/$-(* (unit))}
390+ |* [a=(list) b=$-(* (unit))]
380 |-
391 |-
381 ?~ a ~
392 ?~ a ~
382 =+ c=(b i.a)
393 =+ c=(b i.a)
@@ -384,11 +395,10 @@ Source
384 $(a t.a)
395 $(a t.a)
385 [i=u.c t=$(a t.a)]
396 [i=u.c t=$(a t.a)]
386
397
387−Examples
398+#### Examples
388−--------
389
399
390 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
400 > =a |=(a=@ ?.((gte a 2) ~ (some (add a 10))))
391− > (murn (limo [0 1 2 3 ~]) a)
401+ > (murn `(list @)`[0 1 2 3 ~] a)
392 [i=12 t=[i=13 t=~]]
402 [i=12 t=[i=13 t=~]]
393
403
394
404
@@ -398,33 +408,31 @@ Examples
398
408
399Remove
409Remove
400
410
401−Removes elements from list `c` beginning at inclusive index `a`, removing `b` number of elements.
411+Removes elements from list `c` beginning at inclusive index `a`, removing `b`
412+number of elements.
402
413
403−Accepts
414+#### Accepts
404−-------
405
415
406`c` is a list.
416`c` is a list.
407
417
408−Produces
418+#### Produces
409−--------
410
419
411A `++list`.
420A `++list`.
412
421
413−Source
422+#### Source
414−------
415
423
416 ++ oust :: remove
424 ++ oust :: remove
417 ~/ %oust
425 ~/ %oust
418− |* {{a/@ b/@} c/(list)}
426+ |* [[a=@ b=@] c=(list)]
419 (weld (scag a c) (slag (add a b) c))
427 (weld (scag a c) (slag (add a b) c))
420
428
421−Examples
429+#### Examples
422−--------
423
430
424 > (oust [4 5] "good day, urbit!")
431 > (oust [4 5] "good day, urbit!")
425 "good urbit!"
432 "good urbit!"
433+
426− > (oust [2 2] (limo [1 2 3 4 ~]))
434+ > (oust [2 2] `(list @)`[1 2 3 4 ~])
427− [i=1 t=[i=2 t=~]]
435+ ~[1 2]
428
436
429
437
430
438
@@ -433,35 +441,35 @@ Examples
433
441
434Replicate
442Replicate
435
443
436−Replicate: produces a `++list` containing `a` copies of `b`.
444+Replicate: produces a `list` containing `a` copies of `b`.
445+
446+#### Accepts
437
447
438−Accepts
448+`a` is an atom.
439−-------
440
449
441`b` is a noun.
450`b` is a noun.
442
451
443−Produces
452+#### Produces
444−--------
445
453
446−A list.
454+A list.
447
455
448−Source
456+#### Source
449−------
450
457
451 ++ reap :: replicate
458 ++ reap :: replicate
452 ~/ %reap
459 ~/ %reap
453− |* {a/@ b/*}
460+ |* [a=@ b=*]
454 |- ^- (list _b)
461 |- ^- (list _b)
455 ?~ a ~
462 ?~ a ~
456 [b $(a (dec a))]
463 [b $(a (dec a))]
457
464
458−Examples
465+#### Examples
459−--------
460
466
461 > (reap 20 %a)
467 > (reap 20 %a)
462 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
468 ~[%a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a %a]
469+
463 > (reap 5 ~s1)
470 > (reap 5 ~s1)
464 ~[~s1 ~s1 ~s1 ~s1 ~s1]
471 ~[~s1 ~s1 ~s1 ~s1 ~s1]
472+
465 > `@dr`(roll (reap 5 ~s1) add)
473 > `@dr`(roll (reap 5 ~s1) add)
466 ~s5
474 ~s5
467
475
@@ -472,41 +480,44 @@ Examples
472
480
473Right fold
481Right fold
474
482
475−Right fold: moves right to left across a `++list` `a`, recursively slamming
483+Right fold: moves right to left across a `list` `a`, recursively slamming
476a binary gate `b` with an element from `a` and an accumulator, producing
484a binary gate `b` with an element from `a` and an accumulator, producing
477the final value of the accumulator.
485the final value of the accumulator.
478
486
487+(To "slam" means to call a gate and give it a sample/samples. In this instance,
488+`a` is the list of samples that are given to the gate b.)
489+
479−Accepts
490+#### Accepts
480−-------
491+
492+`a` is a list.
481
493
482`b` is a binary gate.
494`b` is a binary gate.
483
495
484−Produces
496+#### Produces
485−--------
486
497
487The accumulator, which is a noun.
498The accumulator, which is a noun.
488
499
489−Source
500+#### Source
490−------
491
501
492 ++ reel :: right fold
502 ++ reel :: right fold
493 ~/ %reel
503 ~/ %reel
494− |* {a/(list) b/_|=({* *} +<+)}
504+ |* [a=(list) b=_|=([* *] +<+)]
495 |- ^+ +<+.b
505 |- ^+ +<+.b
496 ?~ a
506 ?~ a
497 +<+.b
507 +<+.b
498 (b i.a $(a t.a))
508 (b i.a $(a t.a))
499
509
500
510
501−Examples
511+#### Examples
502−--------
503
512
504 > =sum =|([p=@ q=@] |.((add p q)))
513 > =sum =|([p=@ q=@] |.((add p q)))
505 > (reel (limo [1 2 3 4 5 ~]) sum)
514 > (reel (limo [1 2 3 4 5 ~]) sum)
506 15
515 15
516+
507 > =a =|([p=@ q=@] |.((sub p q)))
517 > =a =|([p=@ q=@] |.((sub p q)))
508 > (reel (limo [6 3 1 ~]) a)
518 > (reel (limo [6 3 1 ~]) a)
509 4
519 4
520+
510 > (reel (limo [3 6 1 ~]) a)
521 > (reel (limo [3 6 1 ~]) a)
511 ! subtract-underflow
522 ! subtract-underflow
512 ! exit
523 ! exit
@@ -519,21 +530,23 @@ Examples
519Left fold
530Left fold
520
531
521Left fold: moves left to right across a list `a`, recursively slamming a
532Left fold: moves left to right across a list `a`, recursively slamming a
522−binary [gate]() `b` with an element from the [`++list`]() and an accumulator,
533+binary gate `b` with an element from the `list` and an accumulator,
523producing the final value of the accumulator.
534producing the final value of the accumulator.
524
535
536+(To "slam" means to call a gate and give it a sample/samples. In this instance,
537+`a` is the list of samples that are given to the gate b.)
538+
525−Accepts
539+#### Accepts
526−-------
527
540
541+`a` is a list.
542+
528−`b` is a binary [gate]().
543+`b` is a binary gate.
529
544
530−Produces
545+#### Produces
531−--------
532
546
533−The accumulator, which is a [noun]().
547+The accumulator, which is a noun.
534
548
535−Source
549+#### Source
536−------
537
550
538 ++ roll :: left fold
551 ++ roll :: left fold
539 ~/ %roll
552 ~/ %roll
@@ -543,8 +556,7 @@ Source
543 +<+.b
556 +<+.b
544 $(a t.a, b b(+<+ (b i.a +<+.b)))
557 $(a t.a, b b(+<+ (b i.a +<+.b)))
545
558
546−Examples
559+#### Examples
547−--------
548
560
549 > =sum =|([p=@ q=@] |.((add p q)))
561 > =sum =|([p=@ q=@] |.((add p q)))
550 > (roll (limo [1 2 3 4 5 ~]) sum)
562 > (roll (limo [1 2 3 4 5 ~]) sum)
@@ -563,21 +575,20 @@ Examples
563
575
564Prefix
576Prefix
565
577
566−Accepts an atom `a` and [list]() `b`, producing the first `a` elements of
578+Accepts an atom `a` and `list` `b`, producing the first `a` elements of
567the front of the list.
579the front of the list.
568
580
569−Accepts
581+#### Accepts
570−-------
582+
583+`a` is an atom.
571
584
572`b` is a list.
585`b` is a list.
573
586
574−Produces
587+#### Produces
575−--------
576
588
577A list of the same type as `b`.
589A list of the same type as `b`.
578
590
579−Source
591+#### Source
580−------
581
592
582 ++ scag :: prefix
593 ++ scag :: prefix
583 ~/ %scag
594 ~/ %scag
@@ -586,13 +597,13 @@ Source
586 ?: |(?=(~ b) =(0 a)) ~
597 ?: |(?=(~ b) =(0 a)) ~
587 [i.b $(b t.b, a (dec a))]
598 [i.b $(b t.b, a (dec a))]
588
599
589−Examples
600+#### Examples
590−--------
591
601
592− > (scag 2 (limo [0 1 2 3 ~]))
602+ > (scag 2 `(list @)`[1 2 3 4 ~])
593− [i=0 t=[i=1 t=~]]
603+ [i=0 t=~[1]]
604+
594− > (scag 10 (limo [1 2 3 4 ~]))
605+ > (scag 10 `(list @)`[1 2 3 4 ~])
595− [i=1 t=[i=2 t=[i=3 t=[i=4 t=~]]]]
606+ [i=1 t=~[2 3 4]]
596
607
597
608
598
609
@@ -601,25 +612,27 @@ Examples
601
612
602Separate
613Separate
603
614
604−Separates a `++list` `a` into two lists - Those elements of `a` who produce
615+Separates a `list` `a` into two lists - Those elements of `a` who produce
605true when slammed to gate `b` and those who produce `%.n`.
616true when slammed to gate `b` and those who produce `%.n`.
606
617
618+(To "slam" means to call a gate and give it a sample/samples. In this instance,
619+`a` is the list of samples that are given to the gate `b`.)
620+
607−Accepts
621+#### Accepts
608−-------
609
622
623+`a` is a list.
624+
610−`b` is a gate that accepts one argument and produces a loobean.
625+`b` is a gate that accepts one argument and produces a flag.
611
626
612−Produces
627+#### Produces
613−--------
614
628
615A cell of two lists.
629A cell of two lists.
616
630
617−Source
631+#### Source
618−------
619
632
620 ++ skid :: separate
633 ++ skid :: separate
621 ~/ %skid
634 ~/ %skid
622− |* {a/(list) b/$-(* ?)}
635+ |* [a=(list) b=$-(* ?)]
623 |- ^+ [p=a q=a]
636 |- ^+ [p=a q=a]
624 ?~ a [~ ~]
637 ?~ a [~ ~]
625 =+ c=$(a t.a)
638 =+ c=$(a t.a)
@@ -627,12 +640,11 @@ Source
627
640
628
641
629
642
630−Examples
643+#### Examples
631−--------
632
644
633− > =a |=(a/@ (gth a 1))
645+ > =a |=(a=@ (gth a 1))
634− > (skid (limo [0 1 2 3 ~]) a)
646+ > (skid `(list @)`[0 1 2 3 ~]) a)
635− [p=[i=2 t=[i=3 t=~]] q=[i=0 t=[i=1 t=~]]]
647+ (skid `(list @)`[0 1 2 3 ~]) a)
636
648
637
649
638
650
@@ -643,36 +655,34 @@ Suffix
643
655
644Cycles through the members of a list `a`, passing them to a gate `b` and
656Cycles through the members of a list `a`, passing them to a gate `b` and
645producing a list of all of the members that produce `%.y`. Inverse of
657producing a list of all of the members that produce `%.y`. Inverse of
646−`++skip`.
658+`skip`.
647
659
648−Accepts
660+#### Accepts
649−-------
661+
662+`a` is a list.
650
663
651`b` is a gate that accepts one argument and produces a boolean.
664`b` is a gate that accepts one argument and produces a boolean.
652
665
653−Produces
666+#### Produces
654−--------
655
667
656−A boolean
668+A flag.
657
669
658−Source
670+#### Source
659−------
660
671
661 ++ skim :: only
672 ++ skim :: only
662 ~/ %skim
673 ~/ %skim
663− |* {a/(list) b/$-(* ?)}
674+ |* [a=(list) b=$-(* ?)]
664 |-
675 |-
665 ^+ a
676 ^+ a
666 ?~ a ~
677 ?~ a ~
667 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
678 ?:((b i.a) [i.a $(a t.a)] $(a t.a))
668
679
669
680
670−Examples
681+#### Examples
671−--------
672
682
673− > =a |=(a/@ (gth a 1))
683+ > =a |=(a=@ (gth a 1))
674− > (skim (limo [0 1 2 3 ~]) a)
684+ > (skim `(list @)`[0 1 2 3 ~] a)
675− [i=2 t=[i=3 t=~]]
685+ [i=2 t=~[3]]
676
686
677
687
678
688
@@ -681,37 +691,35 @@ Examples
681
691
682Except
692Except
683
693
684−Cycles through the members of `++list` `a`, passing them to a gate `b`.
694+Cycles through the members of `list` `a`, passing them to a gate `b`.
685Produces a list of all of the members that produce `%.n`. Inverse of
695Produces a list of all of the members that produce `%.n`. Inverse of
686−`++skim`.
696+`skim`.
697+
698+#### Accepts
687
699
688−Accepts
700+`a` is a list.
689−-------
690
701
691−`b` is a gate that accepts one argument and produces a loobean.
702+`b` is a gate that accepts one argument and produces a flag.
692
703
693−Produces
704+#### Produces
694−--------
695
705
696A list of the same type as `a`.
706A list of the same type as `a`.
697
707
698−Source
708+#### Source
699−------
700
709
701 ++ skip :: except
710 ++ skip :: except
702 ~/ %skip
711 ~/ %skip
703− |* {a/(list) b/$-(* ?)}
712+ |* [a=(list) b=$-(* ?)]
704 |-
713 |-
705 ^+ a
714 ^+ a
706 ?~ a ~
715 ?~ a ~
707 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
716 ?:((b i.a) $(a t.a) [i.a $(a t.a)])
708
717
709
718
710−Examples
719+#### Examples
711−--------
712
720
713− > =a |=(a/@ (gth a 1))
721+ > =a |=(a=@ (gth a 1))
714− > (skip (limo [0 1 2 3 ~]) a)
722+ > (skip `(l)`[0 1 2 3 ~]) a)
715 [i=0 t=[i=1 t=~]]
723 [i=0 t=[i=1 t=~]]
716
724
717
725
@@ -724,30 +732,26 @@ Suffix
724Accepts an atom `a` and list `b`, producing the remaining elements from
732Accepts an atom `a` and list `b`, producing the remaining elements from
725`b` starting at `a`.
733`b` starting at `a`.
726
734
727−Accepts
735+#### Accepts
728−-------
729
736
730`b` is a list.
737`b` is a list.
731
738
732−Produces
739+#### Produces
733−--------
734
740
735A list of the same type as `b`.
741A list of the same type as `b`.
736
742
737−Source
743+#### Source
738−------
739
744
740 ++ slag :: suffix
745 ++ slag :: suffix
741 ~/ %slag
746 ~/ %slag
742− |* {a/@ b/(list)}
747+ |* [a=@ b=(list)]
743 |- ^+ b
748 |- ^+ b
744 ?: =(0 a) b
749 ?: =(0 a) b
745 ?~ b ~
750 ?~ b ~
746 $(b t.b, a (dec a))
751 $(b t.b, a (dec a))
747
752
748
753
749−Examples
754+#### Examples
750−--------
751
755
752 > (slag 2 (limo [1 2 3 4 ~]))
756 > (slag 2 (limo [1 2 3 4 ~]))
753 [i=3 t=[i=4 t=~]]
757 [i=3 t=[i=4 t=~]]
@@ -764,22 +768,19 @@ Index
764Accepts an atom `a` and a `++list` `b`, producing the element at the index
768Accepts an atom `a` and a `++list` `b`, producing the element at the index
765of `a`and failing if the list is null. Lists are 0-indexed.
769of `a`and failing if the list is null. Lists are 0-indexed.
766
770
767−Accepts
771+#### Accepts
768−-------
769
772
770`b` is a list.
773`b` is a list.
771
774
772−Produces
775+#### Produces
773−--------
774
776
775Produces an element of `b`, or crashes if no element exists at that index.
777Produces an element of `b`, or crashes if no element exists at that index.
776
778
777−Source
779+#### Source
778−------
779
780
780 ++ snag :: index
781 ++ snag :: index
781 ~/ %snag
782 ~/ %snag
782− |* {a/@ b/(list)}
783+ |* [a=@ b=(list)]
783 |-
784 |-
784 ?~ b
785 ?~ b
785 ~|('snag-fail' !!)
786 ~|('snag-fail' !!)
@@ -787,8 +788,7 @@ Source
787 $(b t.b, a (dec a))
788 $(b t.b, a (dec a))
788
789
789
790
790−Examples
791+#### Examples
791−--------
792
792
793 > (snag 2 "asdf")
793 > (snag 2 "asdf")
794 ~~d
794 ~~d
@@ -803,25 +803,22 @@ Examples
803Quicksort
803Quicksort
804
804
805Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
805Quicksort: accepts a `++list` `a` and a gate `b` which accepts two nouns and
806−produces a loobean. `++sort` then produces a list of the elements of `a`,
806+produces a flag. `++sort` then produces a list of the elements of `a`,
807sorted according to `b`.
807sorted according to `b`.
808
808
809−Accepts
809+#### Accepts
810−-------
811
810
812`b` is a gate that accepts two nouns and produces a boolean.
811`b` is a gate that accepts two nouns and produces a boolean.
813
812
814−Produces
813+#### Produces
815−--------
816
814
817A list
815A list
818
816
819−Source
817+#### Source
820−------
821
818
822 ++ sort !. :: quicksort
819 ++ sort !. :: quicksort
823 ~/ %sort
820 ~/ %sort
824− |* {a/(list) b/$-([* *] ?)}
821+ |* [a=(list) b=$-([* *] ?)]
825 => .(a ^.(homo a))
822 => .(a ^.(homo a))
826 |- ^+ a
823 |- ^+ a
827 ?~ a ~
824 ?~ a ~
@@ -831,91 +828,14 @@ Source
831 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
828 [i.a $(a (skim t.a |=(c/_i.a !(b c i.a))))]
832
829
833
830
834−Examples
831+#### Examples
835−--------
836
832
837− > =a =|({p/@ q/@} |.((gth p q)))
833+ > =a =|([p/@ q/@] |.((gth p q)))
838 > (sort (limo [0 1 2 3 ~]) a)
834 > (sort (limo [0 1 2 3 ~]) a)
839 ~[3 2 1 0]
835 ~[3 2 1 0]
840
836
841
837
842
838
843−***
844−### `++swag`
845−
846−Infix
847−
848−Similar to `substr` in Javascript: extracts a string infix, beginning at
849−inclusive index `a`, producing `b` number of characters.
850−
851−Accepts
852−-------
853−
854−`c` is a list.
855−
856−Produces
857−--------
858−
859−A list of the same type as `c`.
860−
861−Source
862−------
863−
864− ++ swag :: infix
865− |* {{a/@ b/@} c/(list)}
866− (scag +<-> (slag +<-< c))
867−
868−
869−Examples
870−--------
871−
872− > (swag [2 5] "roly poly")
873− "ly po"
874− > (swag [2 2] (limo [1 2 3 4 ~]))
875− [i=3 t=[i=4 t=~]]
876−
877−
878−
879−***
880−### `++turn`
881−
882−Gate to list
883−
884−Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
885−to each element of the original list.
886−
887−Accepts
888−-------
889−
890−`b` is a gate.
891−
892−Produces
893−--------
894−
895−A list.
896−
897−Source
898−------
899−
900− ++ turn :: transform
901− ~/ %turn
902− |* {a/(list) b/gate}
903− |-
904− ?~ a ~
905− [i=(b i.a) t=$(a t.a)]
906−
907−
908−Examples
909−--------
910−
911− > (turn (limo [104 111 111 110 ~]) @t)
912− <|h o o n|>
913− > =a |=(a/@ (add a 4))
914− > (turn (limo [1 2 3 4 ~]) a)
915− ~[5 6 7 8]
916−
917−
918−
919***
839***
920### `++spin`
840### `++spin`
921
841
@@ -927,8 +847,7 @@ a tuple -- the head is an element of `a` and the tail is the state `c`, and
927should produce a tuple of the transformed element and the (potentially
847should produce a tuple of the transformed element and the (potentially
928modified) state `c`.
848modified) state `c`.
929
849
930−Accepts
850+#### Accepts
931−-------
932
851
933`a` is a `++list`.
852`a` is a `++list`.
934
853
@@ -936,16 +855,14 @@ Accepts
936
855
937`c` is a noun.
856`c` is a noun.
938
857
939−Produces
858+#### Produces
940−--------
941
859
942A list.
860A list.
943
861
944−Source
862+#### Source
945−------
946
863
947 ++ spin
864 ++ spin
948− |* {a/(list) b/_|=({* *} [** +<+]) c/*}
865+ |* [a=(list) b=_|=([* *] [** +<+]) c/*]
949 :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
866 :: ?< ?=($-([_?<(?=($~ a) i.a) _c] [* _c]) b)
950 |-
867 |-
951 ?~ a
868 ?~ a
@@ -954,31 +871,25 @@ Source
954 [i=-.v t=$(a t.a, c +.v)]
871 [i=-.v t=$(a t.a, c +.v)]
955
872
956
873
957−Examples
874+#### Examples
958−--------
959
875
960−A trivial example -- does nothing with the state:
961
876
962− > %^ spin (limo ~[4 5 6])
877+ > %^ spin (limo ~[4 5 6]) :: trivial example -- does nothing with the state
963− |=({n/@ a/@} [n a])
878+ |=([n=@ a=@] [n a])
964 0
879 0
965 ~[4 5 6]
880 ~[4 5 6]
966
881
967−Create a list of pairs, `p` as the index and `q` as the list element:
968−
969− > %^ spin (limo ~[4 5 6])
882+ > %^ spin (limo ~[4 5 6]) :: `p` as the index and `q` as the list element
970− |=({n/@ a/@} [`(pair)`[a n] +(a)])
883+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
971 0
884 0
972 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
885 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
973
886
974−Create 10 random numbers less than `10`:
975−
976− > %^ spin (reap 10 0)
887+ > %^ spin (reap 10 0) :: Create 10 random numbers less than `10`
977− |=({n/@ rng/_og} (rads:rng 10))
888+ |=([n=@ rng=_og] (rads:rng 10))
978 ~(. og eny)
889 ~(. og eny)
979 ~[5 5 9 4 1 7 9 9 9 6]
890 ~[5 5 9 4 1 7 9 9 9 6]
980
891
981−*Notes*:
892+#### Discussion
982
893
983`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
894`(~(rads og eny) 2)` creates a random number less than `2`, seeding the RNG
984with entropy (`eny`). The head of the product is the random number, the tail
895with entropy (`eny`). The head of the product is the random number, the tail
@@ -991,31 +902,27 @@ is the continuation of the RNG.
991
902
992Gate to list, with state
903Gate to list, with state
993
904
994−Accepts a `++list` `a` and a gate `b`. `c` is internal state, initially
905+Accepts a `list` `a` and a gate `b`. `c` is internal state, initially
995derived by *bunting* the tail of the sample of gate `b`, instead of
906derived by *bunting* the tail of the sample of gate `b`, instead of
996being passed in explicitly as in `++spin`. Produces a list with the
907being passed in explicitly as in `++spin`. Produces a list with the
997−gate applied to each element of the original list. `b` is called with a tuple
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
998−-- the head is an element of `a` and the tail is the state `c`, and should
999produce a tuple of the transformed element and the (potentially modified)
909produce a tuple of the transformed element and the (potentially modified)
1000state `c`.
910state `c`.
1001
911
1002−Accepts
912+#### Accepts
1003−-------
1004
913
1005`a` is a `++list`.
914`a` is a `++list`.
1006
915
1007`b` is a gate.
916`b` is a gate.
1008
917
1009−Produces
918+#### Produces
1010−--------
1011
919
1012A list.
920A list.
1013
921
1014−Source
922+#### Source
1015−------
1016
923
1017 ++ spun
924 ++ spun
1018− |* {a/(list) b/_|=({* *} [** +<+])}
925+ |* [a=(list) b=_|=([* *] [** +<+])]
1019 =| c/_+<+.b
926 =| c/_+<+.b
1020 |-
927 |-
1021 ?~ a
928 ?~ a
@@ -1024,24 +931,88 @@ Source
1024 [i=-.v t=$(a t.a, c +.v)]
931 [i=-.v t=$(a t.a, c +.v)]
1025
932
1026
933
1027−Examples
934+#### Examples
1028−--------
1029
935
1030−Create a list of pairs, `p` as the index and `q` as the list element:
1031−
1032− > %+ spun (limo ~[4 5 6])
936+ > %+ spun (limo ~[4 5 6]) ::`p` as the index and `q` as the list element
1033− |=({n/@ a/@} [`(pair)`[a n] +(a)])
937+ |=([n=@ a=@] [`(pair)`[a n] +(a)])
1034 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
938 ~[[p=0 q=4] [p=1 q=5] [p=2 q=6]]
1035
939
1036−Join two lists into a list of pairs, `p` from `l` and `q` from the sample:
940+ > =l (limo ~[7 8 9]) ::joins two lists into a list of pairs
1037−
1038− > =l (limo ~[7 8 9])
1039 > %+ spun (limo ~[4 5 6])
941 > %+ spun (limo ~[4 5 6])
1040− |=({n/@ a/@} [`(pair)`[(snag a l) n] +(a)])
942+ |=([n=@ a=@] [`(pair)`[(snag a l) n] +(a)])
1041 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
943 ~[[p=7 q=4] [p=8 q=5] [p=9 q=6]]
1042
944
1043
945
1044
946
947+***
948+### `++swag`
949+
950+Infix
951+
952+Similar to `substr` in Javascript: extracts a string infix, beginning at
953+inclusive index `a`, producing `b` number of characters.
954+
955+#### Accepts
956+
957+`c` is a list.
958+
959+#### Produces
960+
961+A list of the same type as `c`.
962+
963+#### Source
964+
965+ ++ swag
966+ |* [[a=@ a=@] c=(list)]
967+ (scag +<-> (slag +<-< c))
968+
969+
970+#### Examples
971+
972+ > (swag [2 5] "roly poly")
973+ "ly po"
974+ > (swag [2 2] (limo [1 2 3 4 ~]))
975+ [i=3 t=[i=4 t=~]]
976+
977+
978+
979+***
980+### `++turn`
981+
982+Gate to list
983+
984+Accepts a `++list` `a` and a gate `b`. Produces a list with the gate applied
985+to each element of the original list.
986+
987+#### Accepts
988+
989+`b` is a gate.
990+
991+#### Produces
992+
993+A list.
994+
995+#### Source
996+
997+ ++ turn
998+ ~/ %turn
999+ |* [a=(list) b=gate]
1000+ |-
1001+ ?~ a ~
1002+ [i=(b i.a) t=$(a t.a)]
1003+
1004+
1005+#### Examples
1006+
1007+ > (turn (limo [104 111 111 110 ~]) @t)
1008+ <|h o o n|>
1009+
1010+ > =a |=(a=@ (add a 4))
1011+ > (turn (limo [1 2 3 4 ~]) a)
1012+ ~[5 6 7 8]
1013+
1014+
1015+
1045***
1016***
1046### `++weld`
1017### `++weld`
1047
1018
@@ -1049,25 +1020,22 @@ Concatenate
1049
1020
1050Concatenate two `++list`s `a` and `b`.
1021Concatenate two `++list`s `a` and `b`.
1051
1022
1052−Accepts
1023+#### Accepts
1053−-------
1054
1024
1055`a` and `b` are lists.
1025`a` and `b` are lists.
1056
1026
1057−Source
1027+#### Source
1058−------
1059
1028
1060− ++ weld :: concatenate
1029+ ++ weld
1061 ~/ %weld
1030 ~/ %weld
1062− |* {a/(list) b/(list)}
1031+ |* [a=(list) b=(list)]
1063 => .(a ^.(homo a), b ^.(homo b))
1032 => .(a ^.(homo a), b ^.(homo b))
1064 |- ^+ b
1033 |- ^+ b
1065 ?~ a b
1034 ?~ a b
1066 [i.a $(a t.a)]
1035 [i.a $(a t.a)]
1067
1036
1068
1037
1069−Examples
1038+#### Examples
1070−--------
1071
1039
1072 > (weld "urb" "it")
1040 > (weld "urb" "it")
1073 ~[~~u ~~r ~~b ~~i ~~t]
1041 ~[~~u ~~r ~~b ~~i ~~t]
@@ -1084,23 +1052,20 @@ Perfect weld
1084Concatenate two `++list`s `a` and `b` without losing their type information
1052Concatenate two `++list`s `a` and `b` without losing their type information
1085to homogenization.
1053to homogenization.
1086
1054
1087−Accepts
1055+#### Accepts
1088−-------
1089
1056
1090`a` is a list.
1057`a` is a list.
1091
1058
1092`b` is a list.
1059`b` is a list.
1093
1060
1094−Produces
1061+#### Produces
1095−--------
1096
1062
1097A list.
1063A list.
1098
1064
1099−Source
1065+#### Source
1100−------
1101
1066
1102− ++ welp :: perfect weld
1067+ ++ welp
1103− =| {* *}
1068+ =| [* *]
1104 |%
1069 |%
1105 +- $
1070 +- $
1106 ?~ +<-
1071 ?~ +<-
@@ -1109,8 +1074,7 @@ Source
1109 --
1074 --
1110
1075
1111
1076
1112−Examples
1077+#### Examples
1113−--------
1114
1078
1115 > (welp "foo" "bar")
1079 > (welp "foo" "bar")
1116 "foobar"
1080 "foobar"
@@ -1119,7 +1083,7 @@ Examples
1119 ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1083 ~zod/arvo=/hoon/hoon>? (welp ~[60 61 62] ~[%a %b %c])
1120 [60 61 62 %a %b %c ~]
1084 [60 61 62 %a %b %c ~]
1121 [@ud @ud @ud %a %b %c %~]
1085 [@ud @ud @ud %a %b %c %~]
1122− ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si/3)
1086+ ~zod/arvo=/hoon/hoon> (welp [sa+1 so+2 ~] si=3)
1123 [[%sa 1] [%so 2] %si 3]
1087 [[%sa 1] [%so 2] %si 3]
1124
1088
1125
1089
@@ -1132,20 +1096,17 @@ Cons
1132Turns a `++list` of lists into a single list by promoting the elements of
1096Turns a `++list` of lists into a single list by promoting the elements of
1133each sublist into the higher.
1097each sublist into the higher.
1134
1098
1135−Accepts
1099+#### Accepts
1136−-------
1137
1100
1138A list of lists.
1101A list of lists.
1139
1102
1140−Produces
1103+#### Produces
1141−--------
1142
1104
1143A list.
1105A list.
1144
1106
1145−Source
1107+#### Source
1146−------
1147
1108
1148− ++ zing :: promote
1109+ ++ zing
1149 =| *
1110 =| *
1150 |%
1111 |%
1151 +- $
1112 +- $
@@ -1156,11 +1117,11 @@ Source
1156
1117
1157
1118
1158
1119
1159−Examples
1120+#### Examples
1160−--------
1161
1121
1162 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1122 > (zing (limo [(limo ['a' 'b' 'c' ~]) (limo ['e' 'f' 'g' ~]) (limo ['h' 'i' 'j' ~]) ~]))
1163 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1123 ~['a' 'b' 'c' 'e' 'f' 'g' 'h' 'i' 'j']
1124+
1164 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1125 > (zing (limo [(limo [1 'a' 2 'b' ~]) (limo [3 'c' 4 'd' ~]) ~]))
1165 ~[1 97 2 98 3 99 4 100]
1126 ~[1 97 2 98 3 99 4 100]
1166
1127