on master help sign in
Merge pull request #298 from urbit/rmariani-patch-25
2154baeJoshua Reagan
docs/hoon/library/2i.md+640−250
@@ -8,88 +8,288 @@ navhome: /docs/
8
8
9Map operations
9Map operations
10
10
11− ++ by :: map engine
11+Container arm for map operation arms. A map is a set of key-value pairs. The
12− ~/ %by
12+contained arms inherit its sample map, `a`.
13− |_ a/(map)
14−
15
13
16−Container arm for map operation arms. A map is a set of key, value
14+### Accepts
17−pairs. The contained arms inherit it's sample map, `a`.
18
15
19`a` is a map.
16`a` is a map.
20
17
18+#### Source
19+
21− > ~(. by (my [%a 1] [%b 2] ~))
20+ ++ by
22− <22.znh {a/nlr({p/?($a $b) q/@ud}) <409.ofg 110.xht 1.ztu $151>}>
21+ ~/ %by
22+ =| a=(tree (pair))
23+ =* node ?>(?=(^ a) n.a)
24+
25+#### Examples
23
26
24−------------------------------------------------------------------------
27+ > ~(. by (my [%a 1] [%b 2] ~))
28+ < 27.zjr
29+ { a
30+ ?(
31+ { n/{?(p/$a p/$b) q/@ud}
32+ l/nlr({p/?($b $a) q/@ud})
33+ r/nlr({p/?($b $a) q/@ud})
34+ }
35+ $~
36+ )
37+ <119.wim 31.ohr 1.jmk $143>
38+ }
25
39
40+***
26### `+-all:by`
41### `+-all:by`
27
42
28Logical AND
43Logical AND
29
44
30− +- all :: logical AND
45+Computes the logical AND on the results of slamming every element in map `a`
46+with gate `b`.
47+
48+#### Accepts
49+
50+`a` is a map.
51+
52+`b` is a wet gate.
53+
54+#### Produces
55+
56+A flag.
57+
58+#### Source
59+
60+ +- all
31 ~/ %all
61 ~/ %all
32− |* b/$-(* ?)
62+ |* b=$-(* ?)
33 |- ^- ?
63 |- ^- ?
34 ?~ a
64 ?~ a
35 &
65 &
36 ?&((b q.n.a) $(a l.a) $(a r.a))
66 ?&((b q.n.a) $(a l.a) $(a r.a))
37− ::
38−
39
67
40−Computes the logical AND on the results of slamming every element in map
68+#### Examples
41−`a` with gate `b`. Produces a loobean.
42−
43−`a` is a map.
44−
45−`b` is a wet gate.
46
69
47 > =b (my [['a' 1] ['b' [2 3]] ~])
70 > =b (my [['a' 1] ['b' [2 3]] ~])
48− > (~(all by b) |=(a/* ?@(a & |)))
71+ > (~(all by b) |=(a=* ?@(a & |)))
49 %.n
72 %.n
73+
50 > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
74 > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
51− > (~(all by a) |=(a/@ (lte a 6)))
75+ > (~(all by a) |=(a=@ (lte a 6)))
52 %.y
76 %.y
53− > (~(all by a) |=(a/@ (lte a 4)))
54− %.n
55
77
56−------------------------------------------------------------------------
78+ > (~(all by a) |=(a=@ (lte a 4)))
79+ %.n
57
80
81+***
58### `+-any:by`
82### `+-any:by`
59
83
60Logical OR
84Logical OR
61
85
86+Computes the logical OR on the results of slamming every element with
87+gate `b`.
88+
89+#### Accepts
90+
91+`a` is a map.
92+
93+`b` is a wet gate.
94+
95+#### Produces
96+
97+A flag.
98+
99+#### Source
100+
62− +- any :: logical OR
101+ +- any
63 ~/ %any
102 ~/ %any
64− |* b=$+(* ?)
103+ |* b=$-(* ?)
65 |- ^- ?
104 |- ^- ?
66 ?~ a
105 ?~ a
67 |
106 |
68 ?|((b q.n.a) $(a l.a) $(a r.a))
107 ?|((b q.n.a) $(a l.a) $(a r.a))
69
108
70−Computes the logical OR on the results of slamming every element with
109+#### Examples
71−gate `b`. Produces a loobean.
72−
73−`a` is a map.
74−
75−`b` is a wet gate.
76
110
77 > =b (my [['a' 1] ['b' [2 3]] ~])
111 > =b (my [['a' 1] ['b' [2 3]] ~])
78− > (~(any by b) |=(a/* ?@(a & |)))
112+ > (~(any by b) |=(a=* ?@(a & |)))
79 %.y
113 %.y
114+
80 > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
115 > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
81− > (~(any by a) |=(a/@ (lte a 4)))
116+ > (~(any by a) |=(a=@ (lte a 4)))
82 %.y
117 %.y
83
118
84−------------------------------------------------------------------------
119+***
120+###`+-apt:by`
121+
122+Check correctness
123+
124+Computes whether `a` has a correct horizontal order and a correct vertical
125+order, producing a flag.
126+
127+#### Accepts
128+
129+`a` is a map.
130+
131+#### Produces
132+
133+A flag.
134+
135+#### Source
136+
137+ +- apt
138+ =| [l=(unit) r=(unit)]
139+ |- ^- ?
140+ ?~ a &
141+ ?& ?~(l & (gor p.n.a u.l))
142+ ?~(r & (gor u.r p.n.a))
143+ ?~(l.a & ?&((vor p.n.a p.n.l.a) $(a l.a, l `p.n.a)))
144+ ?~(r.a & ?&((vor p.n.a p.n.r.a) $(a r.a, r `p.n.a)))
145+ ==
146+
147+#### Examples
148+
149+ > =a (my [['a' 1] ['b' [2 3]] ~])
150+ > ~(apt by a)
151+ %.y
152+
153+ > =s (my [[1 2] [3 4] ~])
154+ > =z ?~ s ~ s(p.n 10)
155+ > z
156+ [n=[p=10 q=2] l={} r={[p=3 q=4]}]
157+
158+ > ~(apt by z)
159+ %.n
160+
161+#### Discussion
162+
163+See section [`2f`](../2f) for more information on noun ordering.
164+
165+###`+-bif:by`
166+
167+Bifurcate
168+
169+Splits map `a` into two maps `l` and `r`, with the head at `b` discarded.
170+
171+#### Accepts
172+
173+`a` is a map.
174+
175+`b` is a noun.
176+
177+`c` is a noun.
178+
179+#### Produces
180+
181+A cell of two maps.
182+
183+#### Source
184+
185+ +- bif
186+ ~/ %bif
187+ |* [b=* c=*]
188+ ^+ [l=a r=a]
189+ =< +
190+ |- ^+ a
191+ ?~ a
192+ [[b c] ~ ~]
193+ ?: =(b p.n.a)
194+ ?: =(c q.n.a)
195+ a
196+ [[b c] l.a r.a]
197+ ?: (gor b p.n.a)
198+ =+ d=$(a l.a)
199+ ?> ?=(^ d)
200+ [n.d l.d [n.a r.d r.a]]
201+ =+ d=$(a r.a)
202+ ?> ?=(^ d)
203+ [n.d [n.a l.a l.d] r.d]
204+
205+#### Examples
206+
207+ > =a (my [['a' 1] ['b' 2] ['c' 3] ~])
208+
209+ > (~(bif by a) ['b' 2])
210+ [l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
211+
212+
213+###`+-def:by`
214+
215+Difference
85
216
217+#### Accepts
218+
219+`a` is a map.
220+
221+`b` is a map.
222+
223+#### Produces
224+
225+A map.
226+
227+#### Source
228+
229+ +- def
230+ |* b=_a
231+ ^- (map _p:node (pair (unit _q:node) (unit _q:node)))
232+ !!
233+
234+#### Examples
235+
236+***
237+###`+-dep`
238+
239+Difference as patch
240+
241+
242+#### Accepts
243+
244+`a` is a map.
245+
246+`b` is a map.
247+
248+#### Produces
249+
250+A cell of maps.
251+
252+#### Source
253+
254+ +- dep
255+ |* b=_a
256+ ^+ [p=a q=a]
257+ =+ c=~(tap by (def b))
258+ =+ [d e]=[`_a`~ `_a`~]
259+ |- ^+ [d e]
260+ ?~ c [d e]
261+ %= $
262+ c t.c
263+ d ?~(q.q.i.c d (~(put by d) p.i.c u.q.q.i.c))
264+ e ?~(p.q.i.c e (~(put by e) p.i.c u.p.q.i.c))
265+ ==
266+
267+#### Examples
268+
269+
270+
271+***
86### `+-del:by`
272### `+-del:by`
87
273
88Delete
274Delete
89
275
90− +- del :: delete at key b
276+Produces map `a` with the element located at key `b` removed.
277+
278+#### Accepts
279+
280+`a` is a map.
281+
282+`b` is a key as a noun.
283+
284+#### Produces
285+
286+A map.
287+
288+#### Source
289+
290+ +- del
91 ~/ %del
291 ~/ %del
92− |* b/*
292+ |* b=*
93 |- ^+ a
293 |- ^+ a
94 ?~ a
294 ?~ a
95 ~
295 ~
@@ -97,32 +297,40 @@ Delete
97 ?: (gor b p.n.a)
297 ?: (gor b p.n.a)
98 [n.a $(a l.a) r.a]
298 [n.a $(a l.a) r.a]
99 [n.a l.a $(a r.a)]
299 [n.a l.a $(a r.a)]
100− |- ^- {$?($~ _a)}
300+ |- ^- [(~ _a)]
101 ?~ l.a r.a
301 ?~ l.a r.a
102 ?~ r.a l.a
302 ?~ r.a l.a
103 ?: (vor p.n.l.a p.n.r.a)
303 ?: (vor p.n.l.a p.n.r.a)
104 [n.l.a l.l.a $(l.a r.l.a)]
304 [n.l.a l.l.a $(l.a r.l.a)]
105 [n.r.a $(r.a l.r.a) r.r.a]
305 [n.r.a $(r.a l.r.a) r.r.a]
106− ::
107
306
108−Produces map `a` with the element located at key `b` removed.
307+#### Examples
308+
309+ > =b (my [['a' 1] ['b' [2 3]] ~])
310+ > (~(del by b) 'a')
311+ [n=[p='b' q=[2 3]] l=~ r=~]
312+
313+***
314+### `+-dig:by`
315+
316+Address of key
317+
318+Produce the address of key `b` within map `a`.
319+
320+#### Accepts
109
321
110`a` is a map.
322`a` is a map.
111
323
112`b` is a key as a noun.
324`b` is a key as a noun.
113
325
114− > =b (my [['a' 1] ['b' [2 3]] ~])
326+#### Produces
115− > (~(del by b) 'a')
116− {[p='b' q=[2 3]]}
117
327
118−------------------------------------------------------------------------
328+A unit.
119
329
120−### `+-dig:by`
330+#### Source
121−
122−Axis of key
123
331
124− +- dig :: axis of b key
332+ +- dig
125− |= b/*
333+ |= b=*
126 =+ c=1
334 =+ c=1
127 |- ^- (unit @)
335 |- ^- (unit @)
128 ?~ a ~
336 ?~ a ~
@@ -130,56 +338,74 @@ Axis of key
130 ?: (gor b p.n.a)
338 ?: (gor b p.n.a)
131 $(a l.a, c (peg c 6))
339 $(a l.a, c (peg c 6))
132 $(a r.a, c (peg c 7))
340 $(a r.a, c (peg c 7))
133− ::
134−
135
341
136−Produce the axis of key `b` within map `a`.
137
342
138−`a` is a map.
343+#### Examples
139−
140−`b` is a key as a noun.
141
344
142 > =b (my [['a' 1] ['b' [2 3]] ~])
345 > =b (my [['a' 1] ['b' [2 3]] ~])
143 > (~(dig by b) 'b')
346 > (~(dig by b) 'b')
144− [~ 2]
347+ [~ u=2]
145−
146−------------------------------------------------------------------------
147
348
349+***
148### `+-gas:by`
350### `+-gas:by`
149
351
150Concatenate
352Concatenate
151
353
152− +- gas :: concatenate
153− ~/ %gas
154− |= b/(list _?>(?=(^ a) n.a))
155− |- ^+ a
156− ?~ b
157− a
158− $(b t.b, a (put i.b))
159− ::
160−
161−
162Insert a list of key-value pairs `b` into map `a`.
354Insert a list of key-value pairs `b` into map `a`.
163
355
356+#### Accepts
357+
164`a` is a map.
358`a` is a map.
165
359
166`b` is a list of cells of key-value nouns `p` and `q`.
360`b` is a list of cells of key-value nouns `p` and `q`.
167
361
362+#### Produces
363+
364+A map.
365+
366+#### Source
367+
368+ +- gas
369+ ~/ %gas
370+ |* b=(list [p=* q=*])
371+ => .(b `(list _?>(?=(^ a) n.a))`b)
372+ |- ^+ a
373+ ?~ b
374+ a
375+ $(b t.b, a (put p.i.b q.i.b))
376+
377+#### Examples
378+
168 > =a (my [['a' 1] ['b' 2] ~])
379 > =a (my [['a' 1] ['b' 2] ~])
169 > =b [['c' 3] ['d' 4] ~]
380 > =b [['c' 3] ['d' 4] ~]
170− > (~(gas by a) b)
171− {[p='d' q=4] [p='a' q=1] [p='c' q=3] [p='b' q=2]}
172
381
173−------------------------------------------------------------------------
382+ > (~(gas by a) b)
383+ [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
174
384
385+***
175### `+-get:by`
386### `+-get:by`
176
387
177Grab unit value
388Grab unit value
178
389
179− +- get :: unit value by key
390+Produce the unit value of the value located at key `b` within map `a`.
391+
392+#### Accepts
393+
394+`a` is a map.
395+
396+`b` is a key as a noun.
397+
398+#### Produces
399+
400+A unit.
401+
402+#### Source
403+
404+ +- get
180 ~/ %get
405 ~/ %get
181− |* b=*
406+ |= b=*
182− |- ^- ?(~ [~ u=_?>(?=(^ a) q.n.a)])
407+ ^- [$@(~ [~ u=_?>(?=(^ a) q.n.a)])]
408+ =+ 42
183 ?~ a
409 ?~ a
184 ~
410 ~
185 ?: =(b p.n.a)
411 ?: =(b p.n.a)
@@ -188,77 +414,112 @@ Grab unit value
188 $(a l.a)
414 $(a l.a)
189 $(a r.a)
415 $(a r.a)
190
416
191−Produce the unit value of the value located at key `b` within map `a`.
417+#### Examples
192
418
193−`a` is a map
419+ > =b (my [['a' 1] ['b' [2 3]] ~])
420+ > (~(get by b) 'b')
421+ [~ u=[2 3]]
194
422
195−`b` is a key as a noun
196
423
197− > =b (my [['a' 1] ['b' [2 3]] ~])
424+ > =m (my [['a' 1] ['b' 2] ~])
198− > (~(get by b) 'b')
425+ > (~(get by m) 'a')
199− [~ [2 3]]
426+ [~ u=1]
200
427
201−------------------------------------------------------------------------
202
428
429+***
203### `+-got:by`
430### `+-got:by`
204
431
205Assert
432Assert
206
433
434+Produce the value located at key `b` within map `a`. Crash if key `b` does not
435+exist.
436+
437+#### Accepts
438+
439+`a` is a map.
440+
441+`b` is a key as a noun.
442+
443+#### Produces
444+
445+A noun.
446+
447+#### Source
448+
207 +- got
449 +- got
208− |* b/*
450+ |* b=*
209 (need (get b))
451 (need (get b))
210
452
211−Produce the value located at key `b` within map `a`. Crash if key `b`
453+#### Examples
212−does not exist.
213
454
214−`a` is a map.
455+ > =m (my [['a' 1] ['b' 2] ~])
456+ > m
457+ [n=[p='b' q=2] l={[p='a' q=1]} r={}]
215
458
216−`b` is a key.
459+ > (~(got by m) 'a')
460+ 1
217
461
218− > =m (my [['a' 1] ['b' 2] ~])
219− > m
220− {[p='a' q=1] [p='b' q=2]}
221− > (~(get by m) 'a')
222− [~ 1]
223− > (~(got by m) 'a')
224− 1
225− > (~(got by m) 'c')
462+ > (~(got by m) 'c')
226− ! exit
463+ ! exit
227
464
228−------------------------------------------------------------------------
229
465
466+***
230### `+-has:by`
467### `+-has:by`
231
468
232Key existence check
469Key existence check
233
470
234− +- has :: key existence check
471+Checks whether map `a` contains an element with key `b`, producing a flag.
235− ~/ %has
236− |* b/*
237− !=(~ (get b))
238
472
239−
473+#### Accepts
240−Checks whether map `a` contains an element with key `b`, producing a
241−loobean.
242
474
243`a` is a map.
475`a` is a map.
244
476
245`b` is a key as a noun.
477`b` is a key as a noun.
246
478
247− > =b (my [['a' 1] ['b' [2 3]] ~])
479+#### Produces
248− > (~(has by b) 'b')
480+
249− %.y
481+A flag.
250− > (~(has by b) 'c')
251− %.n
252
482
253−------------------------------------------------------------------------
483+#### Source
254
484
485+ +- has
486+ ~/ %has
487+ |* b=*
488+ !=(~ (get b))
489+
490+#### Examples
491+
492+ > =b (my [['a' 1] ['b' [2 3]] ~])
493+ > (~(has by b) 'b')
494+ %.y
495+
496+ > (~(has by b) 'c')
497+ %.n
498+
499+***
255### `+-int:by`
500### `+-int:by`
256
501
257Intersection
502Intersection
258
503
259− +- int :: intersection
504+Produces a map of the (key) intersection between two maps of the same type, `a`
505+and `b`. If both maps have an identical key that point to different values, the
506+element from map `b` is used.
507+
508+#### Accepts
509+
510+`a` is a map.
511+
512+`b` is a map.
513+
514+#### Produces
515+
516+A map.
517+
518+#### Source
519+
520+ +- int
260 ~/ %int
521 ~/ %int
261− |* b/_a
522+ |* b=_a
262 |- ^+ a
523 |- ^+ a
263 ?~ b
524 ?~ b
264 ~
525 ~
@@ -275,83 +536,98 @@ Intersection
275 ?: (gor p.n.a p.n.b)
536 ?: (gor p.n.a p.n.b)
276 %- uni(a $(b l.b, a [n.a l.a ~])) $(a r.a)
537 %- uni(a $(b l.b, a [n.a l.a ~])) $(a r.a)
277 %- uni(a $(b r.b, a [n.a ~ r.a])) $(a l.a)
538 %- uni(a $(b r.b, a [n.a ~ r.a])) $(a l.a)
278− ::
279
539
280−Produces a map of the (key) intersection between two maps of the same
540+#### Examples
281−type, `a` and `b`. If both maps have an identical key that point to
282−different values, the element from map `b` is used.
283
541
284−`a` is a map.
542+ > =n (my [['a' 1] ['c' 3] ~])
543+ > =m (my [['a' 1] ['b' 2] ~])
285
544
286−`b` is a map.
545+ > (~(int by m) n)
546+ [n=[p='a' q=1] l=~ r=~]
547+
548+ > =p (my [['a' 2] ['b' 2] ~])
549+ > p
550+ [n=[p='b' q=2] l={[p='a' q=2]} r={}]
551+ > (~(int by p) n)
552+ [n=[p='a' q=1] l=~ r=~]
553+
554+ > =q (my [['a' 2] ['c' 2] ~])
555+ > q
556+ [n=[p='c' q=2] l={[p='a' q=2]} r={}]
557+ > (~(int by p) q)
558+ [n=[p='a' q=2] l=~ r=~]
287
559
288− > =n (my [['a' 1] ['c' 3] ~])
289− > n
290− {[p='a' q=1] [p='c' q=3]}
291− > m
292− {[p='a' q=1] [p='b' q=2]}
293− > (~(int by m) n)
294− {[p='a' q=1]}
295− > =p (my [['a' 2] ['b' 2] ~])
296− > p
297− {[p='a' q=2] [p='b' q=2]}
298− > (~(int by p) n)
299− {[p='a' q=1]}
300− > =q (my [['a' 2] ['c' 2] ~])
301− > q
302− {[p='a' q=2] [p='c' q=2]}
303− > (~(int by p) q)
304− {[p='a' q=2]}
305− > =o (my [['c' 3] ['d' 4] ~])
560+ > =o (my [['c' 3] ['d' 4] ~])
306− > (~(int by m) o)
561+ > (~(int by m) o)
307− {}
562+ ~
308−
309−
310−------------------------------------------------------------------------
311
563
564+
565+***
312### `+-mar:by`
566### `+-mar:by`
313
567
314−Assert and Add
568+Assert and add
569+
570+Produces map `a` with the addition of a key-value pair, where the value is a
571+nonempty unit.
315
572
316− +- mar :: add with validation
573+Accept a noun and a unit of a noun of the type of the map's keys and values,
574+respectively. Validate that the value is not null and put the pair in the map.
575+If the value is null, delete the key.
576+
577+#### Accepts
578+
579+`a` is a map.
580+
581+`b` is a unit.
582+
583+#### Produces
584+
585+A map.
586+
587+#### Assert and Add
588+
589+ +- mar
317 |* [b=_?>(?=(^ a) p.n.a) c=(unit ,_?>(?=(^ a) q.n.a))]
590 |* [b=_?>(?=(^ a) p.n.a) c=(unit ,_?>(?=(^ a) q.n.a))]
318 ?~ c
591 ?~ c
319 (del b)
592 (del b)
320 (put b u.c)
593 (put b u.c)
321
594
322−Produces map `a` with the addition of a key-value pair, where the value
595+#### Examples
323−is a nonempty unit.
324−
325−Accept a noun and a unit of a noun of the type of the map's keys and
326−values, respectively. Validate that the value is not null and put the
327−pair in the map. If the value is null, delete the key.
328
596
329−XX This arm is broken, asana task 15186618346453
597+ > =m (my [['a' 1] ['b' 2] ~])
598+ > (~(mar by m) 'c' (some 3))
599+ [n=[p='b' q=2] l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
330
600
331− > m
601+ > (~(mar by m) 'c' ~)
332− {[p='a' q=1] [p='b' q=2]}
602+ [n=[p='b' q=2] l=[n=[p='a' q=1] l=~ r=~] r=~]
333− > (~(mar by m) 'c' (some 3))
334− ! -find-limb.n
335− ! find-none
336− ! exit
337− > (~(mar by m) 'c' ~)
338− ! -find-limb.n
339− ! find-none
340− ! exit
341− > (~(mar by m) 'b' ~)
342− ! -find-limb.n
343− ! find-none
344− ! exit
345
603
346−------------------------------------------------------------------------
604+ > (~(mar by m) 'b' ~)
605+ [n=[p='a' q=1] l=~ r=~]
347
606
607+***
348### `+-put:by`
608### `+-put:by`
349
609
350Add key-value pair
610Add key-value pair
351
611
352− +- put :: adds key-value pair
612+Produces `a` with the addition of the key-value pair of `b` and `c`.
613+
614+#### Accepts
615+
616+`a` is a map.
617+
618+`b` is a key of the same type as the keys in `a`.
619+
620+`c` is a value of the same type of the values in `a`.
621+
622+#### Produces
623+
624+A map.
625+
626+#### Source
627+
628+ +- put
353 ~/ %put
629 ~/ %put
354− |* {b/* c/*}
630+ |* [b=* c=*]
355 |- ^+ a
631 |- ^+ a
356 ?~ a
632 ?~ a
357 [[b c] ~ ~]
633 [[b c] ~ ~]
@@ -370,47 +646,77 @@ Add key-value pair
370 ?: (vor p.n.a p.n.d)
646 ?: (vor p.n.a p.n.d)
371 [n.a l.a d]
647 [n.a l.a d]
372 [n.d [n.a l.a l.d] r.d]
648 [n.d [n.a l.a l.d] r.d]
373− ::
374
649
375−Produces `a` with the addition of the key-value pair of `b` and `c`.
650+#### Examples
376
651
377−`a` is a map.
652+ > =m (my [['a' 1] ['b' 2] ~])
378−
653+ > (~(put by ~) 'c' 3)
379−`b` is a key of the same type as the keys in `a`.
654+ [n=[p='b' q=2] l=[n=[p='c' q=3] l={[p='a' q=1]} r={}] r=~]
380
655
381−`c` is a value of the same type of the values in `a`.
382−
383− > m
384− {[p='a' q=1] [p='b' q=2]}
385− > (~(put by m) 'c' 3)
386− {[p='a' q=1] [p='c' q=3] [p='b' q=2]}
387 > (~(put by m) "zod" 26)
656 > (~(put by m) "zod" 26)
388− ! type-fail
657+ ! nest-fail
389 ! exit
658 ! exit
659+
390 > (~(put by m) 'a' 2)
660 > (~(put by m) 'a' 2)
391− {[p='a' q=2] [p='b' q=2]}
661+ [n=[p='b' q=2] l=[n=[p='a' q=2] l={} r={}] r=~]
662+
663+ > (put:by m 'a' 2)
664+ {[p=[[98 2] [[97 1] 0 0] 0] q=[97 2]]}
392
665
393−------------------------------------------------------------------------
394
666
667+***
395### `+-rep:by`
668### `+-rep:by`
396
669
397− +- rep :: replace by product
670+Replace by product
671+
672+Accumulate elements of map `a` using gate `b`, producing a noun.
673+
674+#### Accepts
675+
676+`a` is a map.
677+
678+`b` is a wet gate.
679+
680+#### Produces
681+
682+A noun.
683+
684+#### Source
685+
686+ +- rep
398− |* b/_|=({* *} +<+)
687+ |* b=_|=([* *] +<+)
399 |-
688 |-
400 ?~ a +<+.b
689 ?~ a +<+.b
401 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
690 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
402− ::
403
691
404−Accumulate using gate from values in map
692+#### Examples
405
693
406−XX interface changing.
694+ > =m (my [['a' 1] ['b' 2] ~])
695+ > (~(rep by m) |=(a=(pair * *) p.a))
696+ q=[97 1]
407
697
408−------------------------------------------------------------------------
409
698
699+***
410### `+-rib:by`
700### `+-rib:by`
411
701
412− +- rib :: transform + product
702+Replace values with accumulator
703+
704+#### Accepts
705+
706+`a` is a map.
707+
708+`b` is a noun.
709+
710+`c` is a wet gate.
711+
712+####
713+
714+A cell of nouns.
715+
716+#### Source
717+
718+ +- rib
413− |* {b/* c/gate}
719+ |* [b=* c=gate]
414 |- ^+ [b a]
720 |- ^+ [b a]
415 ?~ a [b ~]
721 ?~ a [b ~]
416 =+ d=(c n.a b)
722 =+ d=(c n.a b)
@@ -418,77 +724,143 @@ XX interface changing.
418 =+ e=$(a l.a, b -.d)
724 =+ e=$(a l.a, b -.d)
419 =+ f=$(a r.a, b -.e)
725 =+ f=$(a r.a, b -.e)
420 [-.f [n.a +.e +.f]]
726 [-.f [n.a +.e +.f]]
421− ::
422
727
423−Replace values with accumulator
728+#### Examples
424
729
425−XX interface changing, possibly disappearing
730+ > =m (my [['a' 1] ['b' 2] ~])
731+ > (~(rib by m) [1 2] (con by m))
426
732
427−------------------------------------------------------------------------
733+ > (~(rep by m) [1 2] |=(a=(pair * *) p.a))
428
734
735+***
429### `+-run:by`
736### `+-run:by`
430
737
431Transform values
738Transform values
432
739
433− +- run :: apply gate to values
740+Iterates over every value in map `a` using gate `b`, producing a map.
434− |* b/gate
435− |-
436− ?~ a a
437− [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
438
741
439−Iterates over every value in set `a` using gate `b`. Produces a map.
742+#### Accepts
440
743
441`a` is a map.
744`a` is a map.
442
745
443`b` is a wet gate.
746`b` is a wet gate.
444
747
445− > m
748+#### Produces
749+
750+A map.
751+
752+#### Source
753+
754+ +- run
755+ |* b=gate
756+ |-
757+ ?~ a a
758+ [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
759+
760+#### Examples
761+
446− {[p='a' q=1] [p='b' q=2]}
762+ > =m (my [['a' 1] ['b' 2] ~])
763+
447 > ^+(m (~(run by m) dec))
764 > ^+(m (~(run by m) dec))
448− {[p='a' q=0] [p='b' q=1]}
765+ [n=[p='b' q=1] l={[p='a' q=0]} r={}]
766+
449 > `(map @tas @t)`(~(run by m) (cury scot %ux))
767 > `(map @tas @t)`(~(run by m) (cury scot %ux))
450 {[p=%a q='0x1'] [p=%b q='0x2']}
768 {[p=%a q='0x1'] [p=%b q='0x2']}
451
769
452−------------------------------------------------------------------------
453
770
771+***
772+### `+-rut:by`
773+
774+Transform nodes
775+
776+Applies a gate `b` to nodes in map `a`.
777+
778+#### Accepts
779+
780+`a` is a map.
781+
782+`b` is a wet gate.
783+
784+#### Produces
785+
786+A map.
787+
788+#### Source
789+
790+ +- rut
791+ |* b=gate
792+ |-
793+ ?~ a a
794+ [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
795+
796+#### Examples
797+
798+ > =m (my [['a' 1] ['b' 2] ~])
799+
800+***
454### `+-tap:by`
801### `+-tap:by`
455
802
456Listify pairs
803Listify pairs
457
804
458− +- tap :: listify pairs
805+Produces the list of all elements in map `a` that is prepended to list `b`,
459− ~/ %tap
806+which is empty by default.
460− |= b/(list _?>(?=(^ a) n.a))
461− ^+ b
462− ?~ a
463− b
464− $(a r.a, b [n.a $(a l.a)])
465− ::
466
807
467−Produces the list of all elements in map `a` that is prepended to list
808+#### Accepts
468−`b`, which is empty by default.
469
809
470`a` is a map.
810`a` is a map.
471
811
472`b` is a list.
812`b` is a list.
473
813
474− > m
814+#### Produces
815+
816+A list.
817+
818+#### Source
819+
820+ +- tap
821+ =< $
822+ ~/ %tap
823+ =| b=(list _?>(?=(^ a) n.a))
824+ |. ^+ b
825+ ?~ a
826+ b
827+ $(a r.a, b [n.a $(a l.a)])
828+
829+#### Examples
830+
831+ > =m (my [['a' 1] ['b' 2] ~])
475− {[p='a' q=1] [p='b' q=2]}
832+ [n=[p='b' q=2] l={[p='a' q=1]} r={}]
476 > `*`m
833 > `*`m
477 [[98 2] [[97 1] 0 0] 0]
834 [[98 2] [[97 1] 0 0] 0]
835+
478− > (~(tap by m))
836+ > ~(tap by m)
479 ~[[p='b' q=2] [p='a' q=1]]
837 ~[[p='b' q=2] [p='a' q=1]]
480− > `*`(~(tap by m))
838+ > `*`~(tap by m)
481 [[98 2] [97 1] 0]
839 [[98 2] [97 1] 0]
482
840
483−------------------------------------------------------------------------
841+***
484−
485### `+-uni:by`
842### `+-uni:by`
486
843
487Union
844Union
488
845
489− +- uni :: union, merge
846+Produces a map of the union between the keys of `a` and `b`. If `b` shares a
847+key with `a`, the tuple from `b` is preserved.
848+
849+#### Accepts
850+
851+`a` is a map.
852+
853+`b` is a map.
854+
855+#### Produces
856+
857+A map.
858+
859+#### Source
860+
861+ +- uni
490 ~/ %uni
862 ~/ %uni
491− |* b/_a
863+ |* b=_a
492 |- ^+ a
864 |- ^+ a
493 ?~ b
865 ?~ b
494 a
866 a
@@ -506,83 +878,101 @@ Union
506 $(b [n.b $(b l.b, a [n.a l.a ~]) r.b], a r.a)
878 $(b [n.b $(b l.b, a [n.a l.a ~]) r.b], a r.a)
507 $(b [n.b l.b $(b r.b, a [n.a ~ r.a])], a l.a)
879 $(b [n.b l.b $(b r.b, a [n.a ~ r.a])], a l.a)
508
880
509−Produces a map of the union between the keys of `a` and `b`. If `b`
881+#### Examples
510−shares a key with `a`, the tuple from `b` is preserved.
511
882
512−`a` is a map.
883+ > =m (my [['a' 1] ['b' 2] ~])
513
884
514−`b` is a map.
885+ > =o (my [['c' 3] ['d' 4] ~])
515
886
516− > m
517− {[p='a' q=1] [p='b' q=2]}
518− > o
519− {[p='d' q=4] [p='c' q=3]}
520 > (~(uni by m) o)
887 > (~(uni by m) o)
521− {[p='d' q=4] [p='a' q=1] [p='c' q=3] [p='b' q=2]}
888+ [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
889+
522 > (~(uni by m) ~)
890 > (~(uni by m) ~)
523 {[p='a' q=1] [p='b' q=2]}
891 {[p='a' q=1] [p='b' q=2]}
892+
524 > n
893 > n
525 {[p='a' q=1] [p='c' q=3]}
894 {[p='a' q=1] [p='c' q=3]}
526 > (~(uni by o) n)
895 > (~(uni by o) n)
527 {[p='d' q=4] [p='a' q=1] [p='c' q=3]}
896 {[p='d' q=4] [p='a' q=1] [p='c' q=3]}
528
897
529−------------------------------------------------------------------------
530
898
899+***
531### `+-urn:by`
900### `+-urn:by`
532
901
533Turn (with key)
902Turn (with key)
534
903
535− +- urn :: apply gate to nodes
536− |* b/$-({* *} *)
537− |-
538− ?~ a ~
539− [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
540−
541Iterates over every value in map `a` using gate `b`, which accepts both
904Iterates over every value in map `a` using gate `b`, which accepts both
542the key and the value of each element as its sample.
905the key and the value of each element as its sample.
543
906
907+#### Accepts
908+
544`a` is a map.
909`a` is a map.
545
910
546−`b` is a wet gate that accepts two nouns (a key and a value) and
911+`b` is a wet gate that accepts two nouns.
547−produces a noun (the new value).
912+
913+#### Produces
914+
915+A noun.
916+
917+#### Source
918+
919+ +- urn
920+ |* b=$-({* *} *)
921+ |-
922+ ?~ a ~
923+ [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)
924+
925+
926+#### Examples
548
927
549 > m
928 > m
550 {[p='a' q=1] [p='b' q=2]}
929 {[p='a' q=1] [p='b' q=2]}
551
930
552− > (~(urn by m) |=(a/(pair * *) q.a))
931+ > (~(urn by m) |=(a=(pair * *) q.a))
553 {[p='a' q=1] [p='b' q=2]}
932 {[p='a' q=1] [p='b' q=2]}
554
933
555− > (~(urn by m) |=(a/(pair * *) 7))
934+ > (~(urn by m) |=(a=(pair * *) 7))
556 {[p='a' q=7] [p='b' q=7]}
935 {[p='a' q=7] [p='b' q=7]}
557
936
558− > (~(urn by m) |=(a/(pair * *) p.a))
937+ > (~(urn by m) |=(a=(pair * *) p.a))
559 {[p='a' q=97] [p='b' q=98]}
938 {[p='a' q=97] [p='b' q=98]}
560
939
561−------------------------------------------------------------------------
940+***
562
941
563### `+-wyt:by`
942### `+-wyt:by`
564
943
565Depth
944Depth
566
945
567− +- wyt :: depth of map
946+Produce the depth of the tree map `a`.
947+
948+#### Accepts
949+
950+`a` is a map.
951+
952+#### Produces
953+
954+An atom.
955+
956+#### Source
957+
958+ +- wyt
568 |- ^- @
959 |- ^- @
569 ?~(a 0 +((add $(a l.a) $(a r.a))))
960 ?~(a 0 +((add $(a l.a) $(a r.a))))
570
961
571−Produce the depth of the tree map `a`.
962+#### Examples
572
963
573−`a` is a map.
964+ > =m (my [['a' 1] ['b' 2] ~])
965+
966+ > =o (my [['c' 3] ['d' 4] ~])
574
967
575− > m
576− {[p='a' q=1] [p='b' q=2]}
577− > o
578− {[p='d' q=4] [p='c' q=3]}
579 > ~(wyt by m)
968 > ~(wyt by m)
580 2
969 2
970+
581 > ~(wyt by o)
971 > ~(wyt by o)
582 2
972 2
973+
583 > ~(wyt by (~(uni by m) o))
974 > ~(wyt by (~(uni by m) o))
584 4
975 4
585
976
586
977
587−
588***
978***