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