@@ -9,136 +9,221 @@ navhome: /docs/
99
1010Set operations
1111
12−Core whose arms contain a variety of functions that operate on `++set`s. Its sample accepts the input `++set` to be manipulated.
12+Core whose arms contain a variety of functions that operate on `set`s. Its
13+sample accepts the input `set` to be manipulated.
1314
14−Accepts
15−-------
15+#### Accepts
1616
17−A `++set`.
17+A `set`.
1818
19−Source
20−------
19+#### Source
2120
22− ++ in :: set engine
21+ ++ in
2322 ~/ %in
24− |_ a/(set)
23+ |_ a=(set)
2524
26−Examples
27−--------
25+#### Examples
2826
29− > ~(. in (sa "asd"))
27+ > ~(. in (sy "asd"))
3028 <13.evb [nlr(^$1{@tD $1}) <414.fvk 101.jzo 1.ypj %164>]>
3129
3230### `+-all:in`
3331
3432Logical AND
3533
36−Computes the logical AND on every element in `a` slammed with `b`,
37−producing a boolean.
34+Computes the logical AND on every element in `a` slammed with `b`, producing a
35+flag.
3836
39−Accepts
40−-------
37+#### Accepts
4138
42−`a` is a `++set`.
39+`a` is a `set`.
4340
44−`b` is a wet gate that accepts a noun and produces a boolean.
41+`b` is a wet gate that accepts a noun and produces a flag.
4542
46−Produces
47−--------
43+#### Produces
4844
49−A boolean.
45+A flag.
5046
51−Source
52−------
47+#### Source
5348
54− +- all :: logical AND
49+ +- all
5550 ~/ %all
56− |* b/$-(* ?)
51+ |* b=$-(* ?)
5752 |- ^- ?
5853 ?~ a
5954 &
6055 ?&((b n.a) $(a l.a) $(a r.a))
6156
57+#### Examples
6258
63−Examples
64−--------
65−
66− > =b (sa `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
67− > (~(all in b) |=(a/* ?@(+.a & |)))
59+ > =b (sy `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
60+ > (~(all in b) |=(a=* ?@(+.a & |)))
6861 %.n
69− > =b (sa `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
70− > (~(all in b) |=(a/@t (gte a 100)))
71− %.y
7262
73−------------------------------------------------------------------------
63+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
64+ > (~(all in b) |=(a=@t (gte a 100)))
65+ %.y
7466
67+***
7568### `+-any:in`
7669
7770Logical OR
7871
79−Computes the logical OR on every element of `a` slammed with `b`.
72+Computes the logical OR on every element of `a` slammed with `b`, producing a
73+flag.
8074
81−Accepts
82−-------
75+#### Accepts
8376
84−`a` is a `++set`.
77+`a` is a `set`.
8578
86−`b` is a gate that accepts a noun and produces a boolean.
79+`b` is a gate that accepts a noun and produces a flag.
8780
88−Produces
89−--------
81+#### Produces
9082
91−A boolean.
83+A flag.
9284
93−Source
94−------
85+#### Source
9586
96− +- any :: logical OR
87+ +- any
9788 ~/ %any
98− |* b/$-(* ?)
89+ |* b=$-(* ?)
9990 |- ^- ?
10091 ?~ a
10192 |
10293 ?|((b n.a) $(a l.a) $(a r.a))
103− ::
10494
10595
106−Examples
107−--------
96+#### Examples
10897
109− > =b (sa `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
98+ > =b (sy `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
11099 > (~(any in b) |=(a/* ?@(+.a & |)))
111100 %.y
112− > =b (sa `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
113− > (~(any in b) |=(a/@t (lte a 100)))
101+
102+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
103+ > (~(any in b) |=(a=@t (lte a 100)))
114104 %.n
115105
116−------------------------------------------------------------------------
106+***
107+#### `+-apt:in`
108+
109+Check correctness
110+
111+Computes whether `a` has a correct horizontal order and a correct vertical
112+order, producing a flag.
113+
114+#### Accepts
115+
116+`a` is a set.
117117
118+#### Produces
119+
120+A flag.
121+
122+#### Source
123+
124+ +- apt
125+ =| [l=(unit) r=(unit)]
126+ |- ^- ?
127+ ?~ a &
128+ ?& ?~(l & (hor n.a u.l))
129+ ?~(r & (hor u.r n.a))
130+ ?~(l.a & ?&((vor n.a n.l.a) $(a l.a, l `n.a)))
131+ ?~(r.a & ?&((vor n.a n.r.a) $(a r.a, r `n.a)))
132+ ==
133+
134+#### Examples
135+
136+ > ~(apt in ~)
137+ %.y
138+
139+ > =a (sy [1 2 3 4 5 6 ~])
140+ [n=6 l={5 4} r={1 3 2}]
141+ > ~(apt in a)
142+ %.y
143+
144+ > =z ?~ a ~ a(n 7)
145+ > z
146+ [n=7 l={5 4} r={1 3 2}]
147+ > ~(apt in z)
148+ %.n
149+
150+
151+#### Discussion
152+
153+See section [`2f`](../2f) for more information on noun ordering.
154+
155+***
156+### `+-bif:in`
157+
158+Bifurcate
159+
160+Splits set `a` into two sets `l` and `r`, with any noun `b` removed.
161+
162+#### Accepts
163+
164+`a` is a set.
165+
166+`b` is a noun.
167+
168+#### Produces
169+
170+A cell of two sets.
171+
172+#### Source
173+
174+ +- bif
175+ ~/ %bif
176+ |* b=*
177+ ^+ [l=a r=a]
178+ =< [+< +>]
179+ |- ^+ a
180+ ?~ a
181+ [b ~ ~]
182+ ?: =(b n.a)
183+ a
184+ ?: (hor b n.a)
185+ =+ c=$(a l.a)
186+ ?> ?=(^ c)
187+ [n.c l.c [n.a r.c r.a]]
188+ =+ c=$(a r.a)
189+ ?> ?=(^ c)
190+ [n.c [n.a l.a l.c] r.c]
191+
192+
193+#### Examples
194+
195+ > =a (sy `(list @)`[1 2 3 4 5 6 ~])
196+ > a
197+ [n=6 l={5 4} r={1 3 2}]
198+
199+ > (~(bif in a) 6)
200+ [l=[n=4 l=[n=5 l={} r={}] r=~] r=[n=2 l=[n=1 l={} r={3}] r=~]]
201+
202+ > (~(bif in a) 100)
203+ [l=[n=6 l=[n=4 l={5} r={}] r=[n=2 l={1 3} r={}]] r=~]
204+
205+***
118206### `+-del:in`
119207
120208Remove noun
121209
122−Removes `b` from the `++set` `a`.
210+Removes `b` from the `set` `a`.
123211
124−Accepts
125−-------
212+#### Accepts
126213
127214`a` is a set.
128215
129216`b` is a noun.
130217
131−Produces
132−--------
218+#### Produces
133219
134220A set.
135221
136−Source
137−------
222+#### Source
138223
139− +- del :: b without any a
224+ +- del
140225 ~/ %del
141− |* b/*
226+ |* b=*
142227 |- ^+ a
143228 ?~ a
144229 ~
@@ -152,46 +237,95 @@ Source
152237 ?: (vor n.l.a n.r.a)
153238 [n.l.a l.l.a $(l.a r.l.a)]
154239 [n.r.a $(r.a l.r.a) r.r.a]
155− ::
156240
157241
158−Examples
159−--------
160242
161− > =b (sa `(list @t)`['a' 'b' 'c' ~])
243+#### Examples
244+
245+ > =b (sy `(list @t)`['a' 'b' 'c' ~])
162246 > (~(del in b) 'a')
163247 {'c' 'b'}
164− > =b (sa `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
248+
249+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
165250 > (~(del in b) 'john')
166251 {'bonita' 'madeleine' 'daniel'}
252+
167253 > (~(del in b) 'susan')
168254 {'bonita' 'madeleine' 'daniel' 'john'}
169255
170−------------------------------------------------------------------------
171256
257+***
258+### `+-dif:in`
259+
260+Difference
261+
262+Computes the difference between `a` and `b`, producing the set of items in `a`
263+that are not in `b`.
264+
265+#### Accepts
266+
267+`a` is a set.
268+
269+`b` is a set.
270+
271+#### Produces
272+
273+A set.
274+
275+#### Source
276+
277+ +- dif
278+ ~/ %dif
279+ |* b=_a
280+ |- ^+ a
281+ ?~ b
282+ a
283+ =+ c=(bif n.b)
284+ ?> ?=(^ c)
285+ =+ d=$(a l.c, b l.b)
286+ =+ e=$(a r.c, b r.b)
287+ |- ^- {$?($~ _a)}
288+ ?~ e d
289+ ?: (vor n.d n.e)
290+ [n.d l.d $(d r.d)]
291+ [n.e $(e l.e) r.e]
292+
293+
294+#### Examples
295+
296+ > ((~(dif in (sy 1 2 3 ~)) (sy 2 3 4 ~))
297+ [n=1 l=~ r=~]
298+
299+ > (~(dif in (sy 2 3 4 ~)) (sy 1 2 3 ~))
300+ [n=4 l=~ r=~]
301+
302+ > `(set @ud)`((~(dif in (sy 1 2 3 ~)) (sy 2 3 4 ~))
303+ {1}
304+
305+ > `(set @ud)`(~(dif in (sy 2 3 4 ~)) (sy 1 2 3 ~))
306+ {4}
307+
308+***
172309### `+-dig:in`
173310
174−Axis a in b
311+Address b in a
175312
176−Produce the axis of `b` within `a`.
313+Produce the tree address of `b` within `a`.
177314
178−Accepts
179−-------
315+#### Accepts
180316
181−`a` is a `++set`.
317+`a` is a set.
182318
183319`b` is a noun.
184320
185−Produces
186−--------
321+#### Produces
187322
188−The `++unit` of an atom.
323+The `unit` of an atom.
189324
190−Source
191−------
325+#### Source
192326
193− +- dig :: axis of a in b
194− |= b/*
327+ +- dig
328+ |= b=*
195329 =+ c=1
196330 |- ^- (unit @)
197331 ?~ a ~
@@ -199,69 +333,71 @@ Source
199333 ?: (hor b n.a)
200334 $(a l.a, c (peg c 6))
201335 $(a r.a, c (peg c 7))
202− ::
203336
204337
205338
206−Examples
207−--------
339+#### Examples
208340
209− > =a (sa `(list @)`[1 2 3 4 5 6 7 ~])
341+ > =a (sy `(list @)`[1 2 3 4 5 6 7 ~])
210342 > a
211343 {5 4 7 6 1 3 2}
344+
212345 > -.a
213346 n=6
347+
214348 > (~(dig in a) 7)
215349 [~ 12]
350+
216351 > (~(dig in a) 2)
217352 [~ 14]
353+
218354 > (~(dig in a) 6)
219355 [~ 2]
220356
221−------------------------------------------------------------------------
357+#### Discussion
222358
359+For more on the tree addressing system, see section [1b](../1b).
360+
361+***
223362### `+-gas:in`
224363
225364Concatenate
226365
227−Insert the elements of a `++list` `b` into a `++set` `a`.
366+Insert the elements of a `list` `b` into a `set` `a`.
228367
229−Accepts
230−-------
368+#### Accepts
231369
232370`a` is a set.
233371
234372`b` is a list.
235373
236−Produces
237−--------
374+#### Produces
238375
239−A `++set`.
376+A `set`.
240377
241−Source
242−------
378+#### Source
243379
244− +- gas :: concatenate
380+ +- gas
245381 ~/ %gas
246− |= b/(list _?>(?=(^ a) n.a))
382+ |= b=(list _?>(?=(^ a) n.a))
247383 |- ^+ a
248384 ?~ b
249385 a
250386 $(b t.b, a (put i.b))
251− ::
252387
253388
254−Examples
255−--------
389+#### Examples
256390
257391 > b
258392 {'bonita' 'madeleine' 'rudolf' 'john'}
393+
259394 > (~(gas in b) `(list @t)`['14' 'things' 'number' '1.337' ~])
260395 {'1.337' '14' 'number' 'things' 'bonita' 'madeleine' 'rudolf' 'john'}
396+
261397 > (~(gas in s) `(list ,@t)`['1' '2' '3' ~])
262398 {'1' '3' '2' 'e' 'd' 'a' 'c' 'b'}
263399
264−------------------------------------------------------------------------
400+***
265401
266402### `+-has:in`
267403
@@ -269,24 +405,21 @@ b in a?
269405
270406Checks if `b` is an element of `a`, producing a boolean.
271407
272−Accepts
273−-------
408+#### Accepts
274409
275−`a` is a [`++set`]().
410+`a` is a set.
276411
277−`b` is a [noun]().
412+`b` is a noun.
278413
279−Produces
280−--------
414+#### Produces
281415
282416A boolean.
283417
284−Source
285−------
418+#### Source
286419
287− +- has :: b exists in a check
420+ +- has
288421 ~/ %has
289− |* b/*
422+ |* b=*
290423 |- ^- ?
291424 ?~ a
292425 |
@@ -298,42 +431,38 @@ Source
298431 ::
299432
300433
301−Examples
302−--------
434+#### Examples
303435
304− > =a (~(gas in `(set @t)`~) `(list @t)`[`a` `b` `c` ~])
305− > (~(has in a) `a`)
436+ > =a (~(gas in `(set @t)`~) `(list @t)`['a' 'b' 'c' ~])
437+ > (~(has in a) 'a')
306438 %.y
439+
307440 > (~(has in a) 'z')
308441 %.n
309442
310−------------------------------------------------------------------------
311−
443+***
312444### `+-int:in`
313445
314446Intersection
315447
316−Produces a set of the intersection between two `++set`s of the same type,
448+Produces a set of the intersection between two sets of the same type,
317449`a` and `b`.
318450
319−Accepts
320−-------
451+#### Accepts
321452
322453`a` is a set.
323454
324455`b` is a set.
325456
326−Produces
327−--------
457+#### Produces
328458
329−A `++set`.
459+A `set`.
330460
331−Source
332−------
461+#### Source
333462
334− +- int :: intersection
463+ +- int
335464 ~/ %int
336− |* b/_a
465+ |* b=_a
337466 |- ^+ a
338467 ?~ b
339468 ~
@@ -350,44 +479,42 @@ Source
350479
351480
352481
353−Examples
354−--------
482+#### Examples
355483
356− > (~(int in (sa "ac")) (sa "ha"))
357− {~~a}
358− > (~(int in (sa "acmo")) ~)
359− {}
360− > (~(int in (sa "acmo")) (sa "ham"))
361− {~~a ~~m}
362− > (~(int in (sa "acmo")) (sa "lep"))
363− {}
484+ > (~(int in `(set @t)`(sy "acmo")) `(set @t)`(sy "ham"))
485+ [n='m' l={'a'} r={}]
364486
365−------------------------------------------------------------------------
487+ > (~(int in (sy "acmo")) ~)
488+ ~
366489
490+ > (~(int in `(set @t)`(sy "ac")) `(set @t)`(sy "ha"))
491+ [n='a' l={} r={}]
492+
493+ > (~(int in (sy "acmo")) (sy "lep"))
494+ {}
495+
496+***
367497### `+-put:in`
368498
369499Put b in a
370500
371−Add an element `b` to the `++set` `a`.
501+Add an element `b` to the set `a`, producing a set.
372502
373−Accepts
374−-------
503+#### Accepts
375504
376505`a` is a set.
377506
378507`b` is a noun.
379508
380−Produces
381−--------
509+#### Produces
382510
383−A `++set`.
511+A `set`.
384512
385−Source
386−------
513+#### Source
387514
388− +- put :: puts b in a, sorted
515+ +- put
389516 ~/ %put
390− |* b/*
517+ |* b=*
391518 |- ^+ a
392519 ?~ a
393520 [b ~ ~]
@@ -404,175 +531,152 @@ Source
404531 ?: (vor n.a n.c)
405532 [n.a l.a c]
406533 [n.c [n.a l.a l.c] r.c]
407− ::
408534
409535
410−Examples
411−--------
536+#### Examples
412537
413− > =a (~(gas in `(set @t)`~) `(list @t)`[`a` `b` `c` ~])
414− > =b (~(put in a) `d`)
415− > b
416− {`d` `a` `c` `b`}
417− > -.l.+.b
418− n=`d`
538+ > =a (~(gas in `(set @t)`~) `(list @t)`['a' 'b' 'c' ~])
539+ > =b (~(put in a) 'd')
540+ > `(set @t)`b
541+ {'d' 'a' 'c' 'b'}
419542
420−------------------------------------------------------------------------
543+ > -.l.+.b
544+ n='d'
421545
546+***
422547### `+-rep:in`
423548
424549Accumulate
425550
426551Accumulate the elements of `a` using a gate `b`.
427552
428−Accepts
429−--------
553+#### Accepts
430554
431−`a` is a `++set`.
555+`a` is a `set`.
432556
433557`b` is a gate.
434558
435−Produces
436−--------
559+#### Produces
437560
438561A noun.
439562
440−Source
441−------
563+#### Source
442564
443565 +- rep :: replace by product
444− |* b/_|=({* *} +<+)
566+ |* b=_|=([* *] +<+)
445567 |-
446568 ?~ a +<+.b
447569 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
448570
449571
450572
451−Examples
452−--------
573+#### Examples
453574
454575 > =a (~(gas in *(set @)) [1 2 3 ~])
455− > a
576+ > `(set @)`a
456577 {1 3 2}
457− > (~(rep in a) |=([a/@ b/@] (add a b)))
458− 6
459578
460−------------------------------------------------------------------------
579+ > (~(rep in a) |=([a=@ b=@] (add a b)))
580+ b=6
461581
582+***
462583### `+-run:in`
463584
464−Apply gate to set (often called *map*)
585+Apply gate to set
465586
466−Produce a `++set` containing the products of gate `b` applied to each element
587+Produce a `set` containing the products of gate `b` applied to each element
467588in `a`.
468589
469−Accepts
470−-------
590+#### Accepts
471591
472−`a` is a `++set`.
592+`a` is a `set`.
473593
474594`b` is a gate.
475595
476−Produces
477−--------
596+#### Produces
478597
479598A set.
480599
481−Source
482−------
600+#### Source
483601
484− +- run :: apply gate to values
602+ +- run
485603 ~/ %run
486− |* b/gate
487− =| c/(set _?>(?=(^ a) (b n.a)))
604+ |* b=gate
605+ =| c=(set _?>(?=(^ a) (b n.a)))
488606 |- ?~ a c
489607 =. c (~(put in c) (b n.a))
490608 =. c $(a l.a, c c)
491609 $(a r.a, c c)
492610
493611
494−
495−Examples
496−--------
612+#### Examples
497613
498614 > =s (sy ~["a" "A" "b" "c"])
499− > s
615+ > `(set tape)`s
500616 {"A" "a" "c" "b"}
501− > (~(run in s) cuss)
502− {'A' 'C' 'B'}
503617
504−------------------------------------------------------------------------
618+ > (~(run in s) cuss)
619+ {"A" "C" "B"}
505620
621+***
506622### `+-tap:in`
507623
508624Set to list
509625
510−Flattens the `++set` `a` into a `++list`.
626+Flattens the `set` `a` into a `list`.
511627
512−Accepts
513−-------
628+#### Accepts
514629
515630`a` is an set.
516631
517−Produces
518−--------
632+#### Produces
519633
520634A list.
521635
522−Source
523−------
636+#### Source
524637
525− +- tap :: convert to list
638+ +- tap
526639 ~/ %tap
527− |= b/(list _?>(?=(^ a) n.a))
640+ |= b=(list _?>(?=(^ a) n.a))
528641 ^+ b
529642 ?~ a
530643 b
531644 $(a r.a b [n.a $(a l.a)])
532− ::
533645
534646
535647
536−Examples
537−--------
648+#### Examples
538649
539− > =s (sa `(list @t)`['a' 'b' 'c' 'd' 'e' ~])
650+ > =s (sy `(list @t)`['a' 'b' 'c' 'd' 'e' ~])
540651 > s
541− {'e' 'd' 'a' 'c' 'b'}
542− > (~(tap in s) `(list @t)`['1' '2' '3' ~])
543− ~['b' 'c' 'a' 'd' 'e' '1' '2' '3']
544− > b
545− {'bonita' 'madeleine' 'daniel' 'john'}
546− ~zod/try=> (~(tap in b) `(list ,@t)`['david' 'people' ~])
547− ~['john' 'daniel' 'madeleine' 'bonita' 'david' 'people']
652+ [n='e' l={} r={'d' 'a' 'c' 'b'}]
548653
549−------------------------------------------------------------------------
654+ > ~(tap in s)
655+ ~['b' 'c' 'a' 'd' 'e']
550656
657+***
551658### `+-uni:in`
552659
553660Union
554661
555−Produces a set of the union between two [`++set`]()s of the same type, `a` and
662+Produces a set of the union between two sets of the same type, `a` and
556663`b`.
557664
558−Accepts
559−-------
665+#### Accepts
560666
561667`a` is a set.
562668
563669`b` is a set.
564670
565−Produces
566−--------
671+#### Produces
567672
568673A set.
569674
570−Source
571−------
675+#### Source
572676
573− +- uni :: union
677+ +- uni
574678 ~/ %uni
575− |* b/_a
679+ |* b=_a
576680 ?: =(a b) a
577681 |- ^+ a
578682 ?~ b
@@ -593,38 +697,37 @@ Source
593697 ::
594698
595699
596−Examples
597−--------
598700
599− > (~(uni in (sa "ac")) (sa "ha"))
600− {~~a ~~c ~~h}
601− > (~(uni in (sa "acmo")) ~)
602− {~~a ~~c ~~m ~~o}
603− > (~(uni in (sa "acmo")) (sa "ham"))
604− {~~a ~~c ~~m ~~o ~~h}
605− > (~(uni in (sa "acmo")) (sa "lep"))
606− {~~e ~~a ~~c ~~m ~~l ~~o ~~p}
701+#### Examples
702+
703+ > (~(uni in `(set @t)`(sy "ac")) `(set @)`(sy "ha"))
704+ [n='c' l={'a'} r={'h'}]
705+
706+ > (~(uni in `(set @t)`(sy "acmo")) ~)
707+ [n='c' l={'a'} r={'m' 'o'}]
708+
709+ > (~(uni in `(set @t)`(sy "acmo")) `(set @t)`(sy "ham"))
710+ [n='c' l={'a'} r={'m' 'o' 'h'}]
607711
608−------------------------------------------------------------------------
712+ > (~(uni in `(set @t)`(sy "acmo")) `(set @t)`(sy "lep"))
713+ [n='e' l={} r={'a' 'c' 'm' 'l' 'o' 'p'}]
609714
715+***
610716### `+-wyt:in`
611717
612718Set size
613719
614−Produce the number of elements in [`++set`]() `a` as an atom.
720+Produces the number of elements in set `a` as an atom.
615721
616−Accepts
617−-------
722+#### Accepts
618723
619724`a` is an set.
620725
621−Produces
622−--------
726+#### Produces
623727
624728An atom.
625729
626−Source
627−------
730+#### Source
628731
629732 +- wyt :: size of set
630733 |- ^- @
@@ -633,14 +736,13 @@ Source
633736
634737
635738
636−Examples
637−--------
739+#### Examples
638740
639− > =a (~(put in (~(put in (sa)) 'a')) 'b')
741+ > =a (~(put in (~(put in (sy)) 'a')) 'b')
640742 > ~(wyt in a)
641743 2
642− > b
643− {'bonita' 'madeleine' 'daniel' 'john'}
744+
745+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
644746 > ~(wyt in b)
645747 4
646748