on master help sign in
update bar runes
53a668fTinnus Napbus
content/docs/hoon/reference/rune/bar.md+492−280
@@ -4,64 +4,80 @@ weight = 7
4template = "doc.html"
4template = "doc.html"
5aliases = ["docs/reference/hoon-expressions/rune/bar/"]
5aliases = ["docs/reference/hoon-expressions/rune/bar/"]
6+++
6+++
7+
7Core expressions produce cores. A core is a cell of `[battery payload]`.
8Core expressions produce cores. A core is a cell of `[battery payload]`.
8−The `battery` is code, a battery of Nock formulas. The `payload` is the data
9+The `battery` is code, a battery of Nock formulas. The `payload` is the data
9needed to run those formulas correctly.
10needed to run those formulas correctly.
10
11
11−Five core runes (`|=`, `|.`, `|-`, `|*`, and `|$`) produce a
12+Five core runes (`|=`, `|.`, `|-`, `|*`, and `|$`) produce a core with a single
12−core with a single arm, named `$`. As with all arms, we can recompute `$``
13+arm, named `$`. As with all arms, we can recompute `$` with changes, which is
13−with changes, which is useful for recursion among other things.
14+useful for recursion among other things.
15+
16+## `|$` "barbuc"
14
17
15−## Runes
18+Declares a mold builder wet gate with one or more molds as its sample.
16
19
17−### |$ "barbuc"
20+#### Syntax
18
21
19−Declares a mold builder wet gate with one or more molds as its
22+Two arguments, fixed.
20−sample.
21
23
22−##### Syntax
24+Tall form:
23
25
24−Regular:
25```hoon
26```hoon
26−|$ a=(lest term) b=spec
27+|$ sample
28+body
27```
29```
28
30
29−AST:
31+Wide form:
32+
30```hoon
33```hoon
31−[%brbs sample=(lest term) body=spec]
34+|$(sample body)
32```
35```
33
36
34−##### Semantics
37+Irregular form:
35
38
36−`|$` is used to declare a wet gate mold builder that is polymorphic in its input molds. `a` is a `lest` of `term` used as
39+None.
37−identifiers for the input molds. `b` is a structure built from elements of `a`.
40+
38−The output of `|$` is a mold builder obtained by
41+#### AST
39−substituting the input molds parameterized by `a` into `b`.
42+
43+```hoon
44+[%brbc sample=(lest term) body=spec]
45+```
40
46
41−##### Expands to
47+#### Expands to
42
48
43```hoon
49```hoon
44|$ [a b]
50|$ [a b]
45body
51body
46```
52```
53+
47becomes
54becomes
55+
48```hoon
56```hoon
49|* [a=$~(* $-(* *)) b=$~(* $-(* *))]
57|* [a=$~(* $-(* *)) b=$~(* $-(* *))]
50^:
58^:
51body
59body
52```
60```
53
61
62+#### Semantics
63+
64+`|$` is used to declare a wet gate mold builder that is polymorphic in its input
65+molds. `a` is a `lest` of `term` used as identifiers for the input molds. `b` is
66+a structure built from elements of `a`. The output of `|$` is a mold builder
67+obtained by substituting the input molds parameterized by `a` into `b`.
68+
54−##### Discussion
69+#### Discussion
55
70
56A mold builder is a wet gate from one or more molds to a mold. A mold is a
71A mold builder is a wet gate from one or more molds to a mold. A mold is a
57function from nouns to nouns with types that may be partial, is always
72function from nouns to nouns with types that may be partial, is always
58idempotent, and usually the identity function on the noun itself.
73idempotent, and usually the identity function on the noun itself.
59
74
60−`|$` is a restricted form of `|*`. The use of `|$` over `|*` is one of style, as either could
75+`|$` is a restricted form of `|*`. The use of `|$` over `|*` is one of style, as
61−be used to make wet gates that are mold builders. The buc in `|$` is a hint that
76+either could be used to make wet gates that are mold builders. The buc in `|$`
77+is a hint that `|$` is closely related to buc runes, and thus `|$` should be
62−`|$` is closely related to buc runes, and thus `|$` should be used to make mold builders, while `|*` should be used for any other sort of
78+used to make mold builders, while `|*` should be used for any other sort of wet
63−wet gate. Thus, the second argument of `|$` is frequently a buc
79+gate. Thus, the second argument of `|$` is frequently a buc rune. For further
64−rune. For further discussion of wet gates, see the entry for [`|*`](#bartar).
80+discussion of wet gates, see the entry for [`|*`](#-bartar).
65
81
66Like other single-arm cores, the arm for `|$` is named `$` and this can be used to
82Like other single-arm cores, the arm for `|$` is named `$` and this can be used to
67define recursive structures. Note however that Hoon is evaluated eagerly, and so
83define recursive structures. Note however that Hoon is evaluated eagerly, and so
@@ -69,26 +85,31 @@ infinite structures are not permitted.
69
85
70Proper style for `|$` is to enclose the first argument with brackets, even if it
86Proper style for `|$` is to enclose the first argument with brackets, even if it
71is only a single term. The interpeter will accept a single term without brackets
87is only a single term. The interpeter will accept a single term without brackets
72−just fine, but this style is for consistency with the fact that the first argument is a `lest`.
88+just fine, but this style is for consistency with the fact that the first
89+argument is a `lest`.
73
90
74−##### Examples
91+#### Examples
75
92
76```
93```
77−~zod:dojo> =foo |$([a b] [b a])
94+> =foo |$([a b] [b a])
78
95
79−~zod:dojo> =bar (foo [@ @tas])
96+> =bar (foo [@ @tas])
80
97
81−~zod:dojo> (bar %cat 3)
98+> (bar %cat 3)
82[%cat 3]
99[%cat 3]
83```
100```
84
101
102+---
103+
85−### `|_` "barcab"
104+## `|_` "barcab"
86
105
87Produce a **door** (a core with a sample).
106Produce a **door** (a core with a sample).
88
107
89−##### Syntax
108+#### Syntax
109+
110+One fixed argument, then a variable number of `+`-family expressions.
90
111
91−Regular:
112+Tall form:
92
113
93```hoon
114```hoon
94|_ a=spec
115|_ a=spec
@@ -101,21 +122,21 @@ Regular:
101
122
102Note: The `++` rune may be replaced with any other rune in the `+` family.
123Note: The `++` rune may be replaced with any other rune in the `+` family.
103
124
104−AST:
125+Wide form:
105
126
106−```
127+None.
107−[%brcb p=spec q=alas r=(map term tome)]
108−```
109
128
110−##### Semantics
129+Irregular form:
111
130
112−The product of a `|_` expression is a **door**, a core with one or more arms whose payload includes a sample. That is, a door is a cell of `[battery [sample context]]`, where the `battery` contains one or more arms.
131+None.
113
132
114−`a` defines the door sample type and usually includes a name assignment (e.g., `n=@`). `a` is followed by a series of arm definitions, each of which begins with a rune in the `+` family (most of `++`). There must be at least one arm, but there may be arbitrarily many. Each arm must include a name (`b`, `d`, and `f` above), which is followed by the expression (`c`, `e`, and `g` above) that defines the arm product.
133+#### AST
115
134
116−The context of the door is the subject of the `|_` expression.
135+```hoon
136+[%brcb p=spec q=alas r=(map term tome)]
137+```
117
138
118−##### Expands to
139+#### Expands to
119
140
120```hoon
141```hoon
121=| a=spec
142=| a=spec
@@ -127,29 +148,49 @@ The context of the door is the subject of the `|_` expression.
127--
148--
128```
149```
129
150
151+#### Semantics
152+
153+The product of a `|_` expression is a **door**, a core with one or more arms
154+whose payload includes a sample. That is, a door is a cell of `[battery [sample context]]`, where the `battery` contains one or more arms.
155+
156+`a` defines the door sample type and usually includes a name assignment (e.g.,
157+`n=@`). `a` is followed by a series of arm definitions, each of which begins
158+with a rune in the `+` family (most of `++`). There must be at least one arm,
159+but there may be arbitrarily many. Each arm must include a name (`b`, `d`, and
160+`f` above), which is followed by the expression (`c`, `e`, and `g` above) that
161+defines the arm product.
162+
163+The context of the door is the subject of the `|_` expression.
164+
130−##### Discussion
165+#### Discussion
131
166
132−A door is the general case of a gate (function). A gate is a
167+A door is the general case of a gate (function). A gate is a door with only one
133−door with only one arm, which has the name `$`.
168+arm, which has the name `$`.
134
169
135−Calling a door is like calling a gate except the caller also needs
170+Calling a door is like calling a gate except the caller also needs to specify
171+the arm to be computed. So, for example, if you have some door `door` which
136−to specify the arm to be computed. So, for example, if you have some door `door` which contains some arm `arm`, and you want to pass some argument (i.e., input value `arg`), you would call it with `~(arm door arg)`.
172+contains some arm `arm`, and you want to pass some argument (i.e., input value
173+`arg`), you would call it with `~(arm door arg)`.
137
174
138−Because gates are also doors, you can call them the same way. To call the gate `foo` as a door, instead of `(foo baz)` we would write `~($ foo baz)`. This
175+Because gates are also doors, you can call them the same way. To call the gate
176+`foo` as a door, instead of `(foo baz)` we would write `~($ foo baz)`. This is
177+an irregular form for `%~($ foo baz)`,
139−is an irregular form for `%~($ foo baz)`, [%~](/docs/hoon/reference/rune/cen#censig).
178+[%~](/docs/hoon/reference/rune/cen#censig).
140
179
141−##### Examples
180+#### Examples
142
181
143A trivial door:
182A trivial door:
144
183
145```
184```
146−/~zod:dojo> =mol |_ a=@ud
185+> =mol |_ a=@ud
147− ++ succ +(a)
186+ ++ succ +(a)
148− ++ prev (dec a)
187+ ++ prev (dec a)
149− --
188+ --
189+
150−/~zod:dojo> ~(succ mol 1)
190+> ~(succ mol 1)
1512
1912
192+
152−/~zod:dojo> ~(succ mol ~(succ mol ~(prev mol 5)))
193+> ~(succ mol ~(succ mol ~(prev mol 5)))
1536
1946
154```
195```
155
196
@@ -172,103 +213,58 @@ The `ne` door prints a digit in base 10, 16, 32 or 64:
172'c'
213'c'
173```
214```
174
215
175−### `|%` "barcen"
216+---
176
217
177−Produce a core, `[battery payload]`.
218+## `|:` "barcol"
178
219
179−##### Syntax
220+Produce a gate with a custom sample.
180
221
181−Regular:
222+#### Syntax
182
223
183−```hoon
224+Two arguments, fixed.
184−|%
185−++ a=term b=hoon
186−++ c=term d=hoon
187− ...
188−++ e=term f=hoon
189−--
190−```
191−
192−Note: The `++` rune may be replaced with any other rune in the `+` family.
193
225
194−AST:
226+Tall form:
195
227
228+```hoon
229+|: a
230+b
196```
231```
197−[%brcn p=(unit term) q=(map term tome)]
198−```
199−
200−##### Semantics
201−
202−The product of a `|%` expression is a dry core with one or more arms in the battery.
203−
204−The `|%` rune is followed by a series of arm definitions, each of which begins with a rune in the `+` family (most of `++`). There must be at least one arm, but there may be arbitrarily many. Each arm must include a name (`a`, `c`, and `e` above), which is followed by the expression (`b`, `d`, and `f` above) that defines the arm product.
205−
206−The core payload is the subject of the `|%` expression.
207
232
208−##### Discussion
233+Wide form:
209
234
210−A core is a cell of `[battery payload]`, where the `battery` is code and the `payload` is data. The `battery` is one or more arms. An arm is a computation that takes the core itself as its subject.
235+```hoon
211−
212−The `|%` rune is used to construct a core from a series of arm definitions. Each arm definition in the expression begins with an arm rune (`++`, `+$`, or `+*`). These arms make up the `battery`. The subject of the `|%` expression is used to make the core's `payload`.
213−
214−A core is like an "object" in a conventional language, but its
215−attributes (_arms_) are functions on the core, not the core and
216−an argument. A "method" on a core is an arm that produces a gate.
217−
218−##### Examples
219−
220−A trivial core:
221−
222−```
223−~zod:dojo> =foo =+ x=58
224− |%
225− ++ n (add 42 x)
226− ++ g |= b=@
236+|:(a b)
227− (add b n)
228− --
229−~zod:dojo> n.foo
230−100
231−~zod:dojo> (g.foo 1)
232−101
233```
237```
234
238
235−### `|:` "barcol"
239+Irregular form:
236−
237−Produce a gate with a custom sample.
238
240
239−##### Syntax
241+None
240
242
241−Regular:
243+#### AST
242
244
243```hoon
245```hoon
244−|: a=hoon b=hoon
245−```
246−
247−AST:
248−
249−```
250[%brcl p=hoon q=hoon]
246[%brcl p=hoon q=hoon]
251```
247```
252
248
253−##### Semantics
249+#### Semantics
254
250
255−`a` is a Hoon expression whose product type defines which values the gate accepts, and it usually includes a name (e.g., `n=1`). The product of `a` also serves as the default value of the sample. `b` is a Hoon expression that determines the product value of the gate.
251+`a` is a Hoon expression whose product type defines which values the gate accepts, and it usually includes a name (e.g., `n=1`). The product of `a` also serves as the default value of the sample. `b` is a Hoon expression that determines the product value of the gate.
256
252
257−##### Expands to
253+#### Expands to
258
254
259```hoon
255```hoon
260=> ^~ a
256=> ^~ a
261 |. b
257 |. b
262```
258```
263
259
264−##### Discussion
260+#### Discussion
265
261
266−Pick your own default value for the sample. Note that `a` is an ordinary expression, not a type; `|:` doesn't bunt a sample as
262+Pick your own default value for the sample. Note that `a` is an ordinary
267−[`|=`](#bartis) does.
263+expression, not a type; `|:` doesn't bunt a sample as [`|=`](#bartis) does.
268
264
269This is useful if you want a gate to have a sample of a particular type, but you don't want the default value of the gate to be the default value of that type.
265This is useful if you want a gate to have a sample of a particular type, but you don't want the default value of the gate to be the default value of that type.
270
266
271−##### Examples
267+#### Examples
272
268
273```
269```
274> =add-ten |:(n=`@`2 (add n 10))
270> =add-ten |:(n=`@`2 (add n 10))
@@ -280,137 +276,186 @@ This is useful if you want a gate to have a sample of a particular type, but you
28012
27612
281```
277```
282
278
283−### `|.` "bardot"
279+---
284
280
281+## `|%` "barcen"
282+
285−Produce a trap (a core with one arm `$`).
283+Produce a core, `[battery payload]`.
286
284
287−##### Syntax
285+#### Syntax
288
286
289−Regular:
287+Argument: a variable number of `+`-family expressions.
288+
289+Tall form:
290
290
291```hoon
291```hoon
292+|%
293+++ a=term b=hoon
292−|. a=hoon
294+++ c=term d=hoon
295+ ...
296+++ e=term f=hoon
297+--
293```
298```
294
299
295−AST:
300+Note: The `++` rune may be replaced with any other rune in the `+` family.
296
301
297−```
302+Wide form:
298−[%brdt p=hoon]
299−```
300
303
301−##### Semantics
304+None.
302
305
303−A `|.` expression produces a core with a single arm, `$`. The core isn't explicitly given a sample. `a` is a Hoon expression that defines the computation of the `$` arm.
306+Irregular form:
304
307
305−The payload of the core is the subject of the `|.` expression.
308+None.
306
309
307−##### Expands to
310+#### AST
308
311
309```hoon
312```hoon
310−|% ++ $ a=hoon
313+[%brcn p=(unit term) q=(map term tome)]
311−--
312```
314```
313
315
314−##### Discussion
316+#### Semantics
315
317
316−A trap is generally used to defer a computation.
318+The product of a `|%` expression is a dry core with one or more arms in the
319+battery.
317
320
318−##### Examples
321+The `|%` rune is followed by a series of arm definitions, each of which begins
322+with a rune in the `+` family (most of `++`). There must be at least one arm,
323+but there may be arbitrarily many. Each arm must include a name (`a`, `c`, and
324+`e` above), which is followed by the expression (`b`, `d`, and `f` above) that
325+defines the arm product.
319
326
320−A trivial trap:
327+The core payload is the subject of the `|%` expression.
321
328
322−```
329+#### Discussion
323−~zod:dojo> =foo |.(42)
324
330
325−~zod:dojo> $:foo
331+A core is a cell of `[battery payload]`, where the `battery` is code and the
326−42
332+`payload` is data. The `battery` is one or more arms. An arm is a computation
333+that takes the core itself as its subject.
327
334
328−~zod:dojo> (foo)
335+The `|%` rune is used to construct a core from a series of arm definitions. Each
329−42
336+arm definition in the expression begins with an arm rune (`++`, `+$`, or `+*`).
330−```
337+These arms make up the `battery`. The subject of the `|%` expression is used to
338+make the core's `payload`.
331
339
332−A more interesting trap:
340+A core is like an "object" in a conventional language, but its attributes
341+(_arms_) are functions on the core, not the core and an argument. A "method" on
342+a core is an arm that produces a gate.
343+
344+#### Examples
345+
346+A trivial core:
333
347
334```
348```
335−~zod:dojo> =foo =/ reps 10
349+> =foo =+ x=58
336− =/ step 0
350+ |%
337− =/ outp 0
351+ ++ n (add 42 x)
338− |.
352+ ++ g |= b=@
339− ?: =(step reps)
353+ (add b n)
340− outp
354+ --
341− $(outp (add outp 2), step +(step))
355+
356+> n.foo
357+100
358+
342−~zod:dojo> (foo)
359+> (g.foo 1)
343−20
360+101
344```
361```
345
362
346−Note that we can use `$()` to recurse back into the
363+---
347−trap, since it's a core with an `$` arm.
348
364
349−> `$(...)` expands to `%=($ ...)` (["centis"](/docs/hoon/reference/rune/cen#centis)).
365+## `|.` "bardot"
350
366
351−### `|-` "barhep"
367+Produce a trap (a core with one arm `$`).
352
368
353−Produce a trap (a core with one arm `$`) and evaluate it.
369+#### Syntax
354
370
355−##### Syntax
371+One argument, fixed.
356
372
357−Regular:
373+Tall form:
358
374
359```hoon
375```hoon
360−|- a=hoon
376+|. a
361```
377```
362
378
363−AST:
379+Wide form:
364
380
365−```
381+```hoon
366−[%brhp p=hoon]
382+|.(a)
367```
383```
368
384
369−##### Semantics
385+Irregular form:
370
386
371−A `|-` expression produces a core with one arm named `$` and immediately evaluates `$`. `a` is a Hoon expression that determines what `$` evaluates to.
387+None.
372
388
373−##### Expands to
389+#### AST
374
390
375```hoon
391```hoon
376−=<($ |.(a=hoon))
392+[%brdt p=hoon]
377```
393```
378
394
379−##### Discussion
395+#### Expands to
380
396
381−The `|-` rune can be thought of as a 'recursion point' or a 'loop starting point'. Since `|-` makes a `|.` (["bardot"](#bardot), a core with one arm named `$`, we can recurse back into it with `$()`.
397+```hoon
398+|% ++ $ a=hoon
399+--
400+```
382
401
383−> `$(...)` expands to `%=($ ...)` (["centis"](/docs/hoon/reference/rune/cen#centis)).
402+#### Semantics
384
403
385−##### Examples
404+A `|.` expression produces a core with a single arm, `$`. The core isn't
405+explicitly given a sample. `a` is a Hoon expression that defines the computation
406+of the `$` arm.
386
407
387−A trivial computation doesn't recurse:
408+The payload of the core is the subject of the `|.` expression.
409+
410+#### Discussion
411+
412+A trap is generally used to defer a computation.
413+
414+#### Examples
415+
416+A trivial trap:
388
417
389```
418```
390−~zod:dojo> |-(42)
419+> =foo |.(42)
420+
421+> $:foo
422+42
423+
424+> (foo)
39142
42542
392```
426```
393
427
394−The classic loop is a decrement:
428+A more interesting trap:
395
429
396```
430```
397−~zod:dojo> =foo =/ a 42
431+> =foo =/ reps 10
398− =/ b 0
432+ =/ step 0
399− |-
433+ =/ outp 0
400− ?: =(a +(b))
434+ |.
401− b
435+ ?: =(step reps)
402− $(b +(b))
436+ outp
437+ $(outp (add outp 2), step +(step))
438+
403−~zod:dojo> foo
439+> (foo)
404−41
440+20
405```
441```
406
442
443+Note that we can use `$()` to recurse back into the
444+trap, since it's a core with an `$` arm.
445+
446+> `$(...)` expands to `%=($ ...)` (["centis"](/docs/hoon/reference/rune/cen#centis)).
447+
448+---
449+
407−### `|^` "barket"
450+## `|^` "barket"
408
451
409Produce a core whose battery includes a `$` arm and compute the latter.
452Produce a core whose battery includes a `$` arm and compute the latter.
410
453
411−##### Syntax
454+#### Syntax
455+
456+One fixed argument, then a variable number of `+`-family expressions.
412
457
413−Regular:
458+Tall form:
414
459
415```hoon
460```hoon
416|^ a=hoon
461|^ a=hoon
@@ -423,17 +468,21 @@ Regular:
423
468
424Note: The `++` rune may be replaced with any other rune in the `+` family.
469Note: The `++` rune may be replaced with any other rune in the `+` family.
425
470
426−AST:
471+Wide form:
427
472
428−```
473+None.
429−[%brkt p=hoon q=(map term tome)]
474+
430−```
475+Irregular form:
431
476
432−##### Semantics
477+None.
433
478
434−A `|^` expression produces a multi-arm core whose battery includes a `$` arm, which is evaluated immediately. `a` is a Hoon expression that defines the product of the `$` arm. `a` is followed by a series of arm definitions for the rest of the core battery arms. There must be at least one arm other than the `$` arm.
479+#### AST
480+
481+```hoon
482+[%brkt p=hoon q=(map term tome)]
483+```
435
484
436−##### Expands to
485+#### Expands to
437
486
438```hoon
487```hoon
439=> |%
488=> |%
@@ -446,86 +495,194 @@ A `|^` expression produces a multi-arm core whose battery includes a `$` arm, wh
446$
495$
447```
496```
448
497
498+#### Semantics
499+
500+A `|^` expression produces a multi-arm core whose battery includes a `$` arm,
501+which is evaluated immediately. `a` is a Hoon expression that defines the
502+product of the `$` arm. `a` is followed by a series of arm definitions for the
503+rest of the core battery arms. There must be at least one arm other than the `$`
504+arm.
505+
449−##### Discussion
506+#### Discussion
450
507
451−The `|^` rune is useful when you define a multi-arm core in your code and a particular arm in it is to be evaluated immediately.
508+The `|^` rune is useful when you define a multi-arm core in your code and a
509+particular arm in it is to be evaluated immediately.
452
510
453−##### Examples
511+#### Examples
454
512
455A trivial example:
513A trivial example:
456
514
457```
515```
458−~zod:dojo> |^
516+> |^
459− (add n g)
517+ (add n g)
460− ++ n 42
518+ ++ n 42
461− ++ g 58
519+ ++ g 58
462− --
520+ --
463100
521100
464```
522```
465
523
466−### `|~` "barsig"
524+---
467
525
468−Produce an iron gate.
526+## `|-` "barhep"
527+
528+Produce a trap (a core with one arm `$`) and evaluate it.
469
529
470−##### Syntax
530+#### Syntax
471
531
472−Regular:
532+One argument, fixed.
533+
534+Tall form:
473
535
474```hoon
536```hoon
475−|~ a=spec b=hoon
537+|- a
476```
538```
477
539
478−AST:
540+Wide form:
479
541
542+```hoon
543+|-(a)
480```
544```
545+
546+Irregular form:
547+
548+None.
549+
550+#### AST
551+
552+```hoon
553+[%brhp p=hoon]
554+```
555+
556+#### Expands to
557+
558+```hoon
481−[%brsg p=spec q=hoon]
559+=<($ |.(a=hoon))
560+```
561+
562+#### Semantics
563+
564+A `|-` expression produces a core with one arm named `$` and immediately
565+evaluates `$`. `a` is a Hoon expression that determines what `$` evaluates to.
566+
567+#### Discussion
568+
569+The `|-` rune can be thought of as a 'recursion point' or a 'loop starting
570+point'. Since `|-` makes a `|.` (["bardot"](#bardot), a core with one arm named
571+`$`, we can recurse back into it with `$()`.
572+
573+> `$(...)` expands to `%=($ ...)` (["centis"](/docs/hoon/reference/rune/cen#centis)).
574+
575+#### Examples
576+
577+A trivial computation doesn't recurse:
578+
579+```
580+> |-(42)
581+42
582+```
583+
584+The classic loop is a decrement:
585+
586+```
587+> =foo =/ a 42
588+ =/ b 0
589+ |-
590+ ?: =(a +(b))
591+ b
592+ $(b +(b))
593+
594+> foo
595+41
596+```
597+
598+---
599+
600+## `|~` "barsig"
601+
602+Produce an iron gate.
603+
604+#### Syntax
605+
606+Two arguments, fixed.
607+
608+Tall form:
609+
610+```hoon
611+|~ a
612+b
613+```
614+
615+Wide form:
616+
617+```hoon
618+|~(a b)
482```
619```
483
620
484−##### Semantics
621+Irregular form:
622+
623+None.
485
624
486−A `|~` expression produces an iron gate. `a` defines the sample, and `b` defines the output value of the gate.
625+#### AST
626+
627+```hoon
628+[%brsg p=spec q=hoon]
629+```
487
630
488−##### Expands to
631+#### Expands to
489
632
490```hoon
633```hoon
491^| |=(a b)
634^| |=(a b)
492```
635```
493
636
637+#### Semantics
638+
639+A `|~` expression produces an iron gate. `a` defines the sample, and `b` defines
640+the output value of the gate.
641+
494−##### Discussion
642+#### Discussion
495
643
496See [this discussion of core variance models](/docs/hoon/reference/advanced)
644See [this discussion of core variance models](/docs/hoon/reference/advanced)
497
645
498−##### Examples
646+#### Examples
499
647
500```
648```
501−~zod:dojo> => ~ ^+(|~(a=@ *@) |=(a=* *@))
649+> => ~ ^+(|~(a=@ *@) |=(a=* *@))
502<1|usl {a/@ $~}>
650<1|usl {a/@ $~}>
503```
651```
504
652
653+---
654+
505−### `|*` "bartar"
655+## `|*` "bartar"
506
656
507Produce a wet gate (one-armed core with sample).
657Produce a wet gate (one-armed core with sample).
508
658
509−##### Syntax
659+#### Syntax
660+
661+Two arguments, fixed.
510
662
511−Regular:
663+Tall form:
512
664
513```hoon
665```hoon
514−|* a=spec b=hoon
666+|* a b
515```
667```
516
668
517−AST:
669+Wide form:
518
670
671+```hoon
672+|*(a b)
519```
673```
520−[%brtr p=spec q=hoon]
521−```
522
674
523−##### Semantics
675+Irregular form:
676+
677+None.
524
678
525−A `|*` expression produces a wet gate. `a` defines the gate's sample, and `b`
679+#### AST
526−is a Hoon expression that determines the output value of the gate.
680+
681+```hoon
682+[%brtr p=spec q=hoon]
683+```
527
684
528−##### Expands to
685+#### Expands to
529
686
530```hoon
687```hoon
531=| a
688=| a
@@ -535,14 +692,19 @@ is a Hoon expression that determines the output value of the gate.
535--
692--
536```
693```
537
694
695+#### Semantics
696+
697+A `|*` expression produces a wet gate. `a` defines the gate's sample, and `b` is
698+a Hoon expression that determines the output value of the gate.
699+
538−##### Discussion
700+#### Discussion
539
701
540In a normal (dry) gate, your argument is converted into the
702In a normal (dry) gate, your argument is converted into the
541−sample type. In a generic (wet) gate, your argument type
703+sample type. In a generic (wet) gate, your argument type
542passes through the function, rather as if it were a macro (there
704passes through the function, rather as if it were a macro (there
543is still only one copy of the code, however).
705is still only one copy of the code, however).
544
706
545−Genericity is a powerful and dangerous tool. Use wet gates only if
707+Genericity is a powerful and dangerous tool. Use wet gates only if
546you know what you're doing.
708you know what you're doing.
547
709
548Just as with a [gate](#bartis), we can recurse back into a wet gate
710Just as with a [gate](#bartis), we can recurse back into a wet gate
@@ -553,50 +715,59 @@ with `$()`.
553`|*` can be used to make wet gates that produce structures, but this usage is
715`|*` can be used to make wet gates that produce structures, but this usage is
554discouraged in favor of `|$`.
716discouraged in favor of `|$`.
555
717
556−##### Examples
718+#### Examples
557
719
558Wet and dry gates in a nutshell:
720Wet and dry gates in a nutshell:
559
721
560```
722```
561−~zod:dojo> =foo |=([a=* b=*] [b a])
723+> =foo |=([a=* b=*] [b a])
562
724
563−~zod:dojo> =bar |*([a=* b=*] [b a])
725+> =bar |*([a=* b=*] [b a])
564
726
565−~zod:dojo> (foo %cat %dog)
727+> (foo %cat %dog)
566[6.778.724 7.627.107]
728[6.778.724 7.627.107]
567
729
568−~zod:dojo> (bar %cat %dog)
730+> (bar %cat %dog)
569[%dog %cat]
731[%dog %cat]
570```
732```
571
733
572The dry gate does not preserve the type of `a` and `b`; the wet
734The dry gate does not preserve the type of `a` and `b`; the wet
573gate does.
735gate does.
574
736
737+---
738+
575−### `|=` "bartis"
739+## `|=` "bartis"
576
740
577Produce a gate (a one-armed core with a sample).
741Produce a gate (a one-armed core with a sample).
578
742
579−##### Syntax
743+#### Syntax
744+
745+Two arguments, fixed.
580
746
581−Regular:
747+Tall form:
582
748
583```hoon
749```hoon
584−|= a=spec b=hoon
750+|= a
751+b
585```
752```
586
753
587−AST:
754+Wide form:
588
755
589−```
756+```hoon
590−[%brts p=spec q=hoon]
757+|=(a b)
591```
758```
592
759
593−##### Definition
760+Irregular form:
594
761
595−The product of a `|=` expression is a dry **gate**, i.e., a Hoon function.
762+None.
596
763
597−`p` defines the gate sample type -- i.e., the input value type -- and usually includes a sample name assignment (e.g., `a=@`). `q` is an expression that determines the output value of the gate.
764+#### AST
765+
766+```hoon
767+[%brts p=spec q=hoon]
768+```
598
769
599−##### Expands to
770+#### Expands to
600
771
601```hoon
772```hoon
602=| a=spec
773=| a=spec
@@ -604,7 +775,15 @@ The product of a `|=` expression is a dry **gate**, i.e., a Hoon function.
604--
775--
605```
776```
606
777
778+#### Definition
779+
780+The product of a `|=` expression is a dry **gate**, i.e., a Hoon function.
781+
782+`p` defines the gate sample type -- i.e., the input value type -- and usually
783+includes a sample name assignment (e.g., `a=@`). `q` is an expression that
784+determines the output value of the gate.
785+
607−##### Discussion
786+#### Discussion
608
787
609Dry gates are used for the vast majority of ordinary functions in Hoon.
788Dry gates are used for the vast majority of ordinary functions in Hoon.
610
789
@@ -612,33 +791,38 @@ A gate is a core with one arm named `$`, so we can recurse back into it with `$(
612
791
613> `$(...)` expands to `%=($ ...)` (["centis"](/docs/hoon/reference/rune/cen#centis)).
792> `$(...)` expands to `%=($ ...)` (["centis"](/docs/hoon/reference/rune/cen#centis)).
614
793
615−##### Examples
794+#### Examples
616
795
617A trivial gate:
796A trivial gate:
618
797
619```
798```
620−~zod:dojo> =foo |=(a=@ +(a))
799+> =foo |=(a=@ +(a))
621
800
622−~zod:dojo> (foo 20)
801+> (foo 20)
62321
80221
624```
803```
625
804
626A slightly less trivial gate:
805A slightly less trivial gate:
627
806
628```
807```
629−~zod:dojo> =foo |= [a=@ b=@]
808+> =foo |= [a=@ b=@]
630− (add a b)
809+ (add a b)
810+
631−~zod:dojo> (foo 30 400)
811+> (foo 30 400)
632430
812430
633```
813```
634
814
815+---
816+
635−### `|@` "barpat"
817+## `|@` "barpat"
636
818
637Produce a 'wet' core `[battery payload]`.
819Produce a 'wet' core `[battery payload]`.
638
820
639−##### Syntax
821+#### Syntax
640
822
641−Regular:
823+Arguments: a variable number of `+`-family expressions.
824+
825+Tall form:
642
826
643```hoon
827```hoon
644|@
828|@
@@ -651,58 +835,86 @@ Regular:
651
835
652Note: The `++` rune may be replaced with any other rune in the `+` family.
836Note: The `++` rune may be replaced with any other rune in the `+` family.
653
837
654−AST:
838+Wide form:
655
839
840+None.
841+
842+Irregular form:
843+
844+None.
845+
846+#### AST
847+
656−```
848+```hoon
657[%brpt p=(unit term) q=(map term tome)]
849[%brpt p=(unit term) q=(map term tome)]
658```
850```
659
851
660−##### Semantics
852+#### Semantics
853+
854+A `|@` expression produces a 'wet' core whose payload is the expression's
855+subject. The various arms in the battery are each named (`a`, `c`, and `e`
856+above) and defined explicitly with a Hoon expression (with `b`, `d`, and `f`
857+above).
661
858
662−A `|@` expression produces a 'wet' core whose payload is the expression's subject. The various arms in the battery are each named (`a`, `c`, and `e` above) and defined explicitly with a Hoon expression (with `b`, `d`, and `f` above).
859+#### Discussion
663
860
664−##### Discussion
861+The `|@` rune is just like the `|%` rune except that instead of producing a
862+'dry' core, it produces a 'wet' one. This allows for type polymorphism of its
863+arms, using 'genericity'. See [Advanced types](/docs/hoon/reference/advanced).
665
864
666−The `|@` rune is just like the `|%` rune except that instead of producing a 'dry' core, it produces a 'wet' one. This allows for type polymorphism of its arms, using 'genericity'. See [Advanced types](/docs/hoon/reference/advanced).
865+---
667
866
668−### `|?` "barwut"
867+## `|?` "barwut"
669
868
670Produce a lead trap.
869Produce a lead trap.
671
870
672−##### Syntax
871+#### Syntax
673
872
674−Regular:
873+One argument, fixed.
874+
875+Tall form:
675
876
676```hoon
877```hoon
677−|? a=hoon
878+|? a
678```
879```
679
880
680−AST:
881+Wide form:
681
882
682−```
683−[%brwt p=hoon]
883+```hoon
884+|?(a)
684```
885```
685
886
686−##### Semantics
887+Irregular form:
687
888
688−A `|?` expression produces a lead trap (i.e., a lead core with one arm named `$`). `a` is a Hoon expression that defines what the `$` arm does.
889+None.
689
890
891+#### AST
892+
893+```hoon
894+[%brwt p=hoon]
895+```
896+
690−##### Expands to
897+#### Expands to
691
898
692```hoon
899```hoon
693^? |. a
900^? |. a
694```
901```
695
902
903+#### Semantics
904+
905+A `|?` expression produces a lead trap (i.e., a lead core with one arm named
906+`$`). `a` is a Hoon expression that defines what the `$` arm does.
907+
696−##### Discussion
908+#### Discussion
697
909
698See this [discussion of the core variance model](/docs/hoon/reference/advanced).
910See this [discussion of the core variance model](/docs/hoon/reference/advanced).
699
911
700−##### Examples
912+#### Examples
701
913
702```
914```
703−~zod:dojo> => ~ ^+ |?(%a) |.(%a)
915+> => ~ ^+ |?(%a) |.(%a)
704<1?pqz $~>
916<1?pqz $~>
705
917
706−~zod:dojo> => ~ ^+ |?(%a) |.(%b)
918+> => ~ ^+ |?(%a) |.(%b)
707nest-fail
919nest-fail
708```
920```