@@ -4,127 +4,254 @@ weight = 5
4template = "doc.html"
4template = "doc.html"
7−These runes modify the subject. (Or more precisely, they
7+These runes modify the subject. (Or more precisely, they
8evaluate at least one of their subexpressions with a modified subject.)
8evaluate at least one of their subexpressions with a modified subject.)
10## Overview
10## Overview
12−Hoon doesn't have variables in the ordinary sense. If you want to bind a name
12+Hoon doesn't have variables in the ordinary sense. If you want to bind a name
13to a value, e.g., `a` to `12`, you do so by pinning `12` to the subject and
13to a value, e.g., `a` to `12`, you do so by pinning `12` to the subject and
14−associating the name with it. This sort of operation is done with the `=`
14+associating the name with it. This sort of operation is done with the `=`
15family of runes.
15family of runes.
17−Let's say you have some old subject `p`. To 'pin' a value to the head means to
17+Let's say you have some old subject `p`. To 'pin' a value to the head means to
18−modify the subject by repacing it with a cell of `[new-value p]`. The head of
18+modify the subject by repacing it with a cell of `[new-value p]`. The head of
19−the cell is the new value. So to pin `12` with the face `a` the new subject
19+the cell is the new value. So to pin `12` with the face `a` the new subject
20would be: `[a=12 p]`.
20would be: `[a=12 p]`.
22Of course there are many variations on ways to modify the subject, useful for
22Of course there are many variations on ways to modify the subject, useful for
23−different situations. Hence the whole family of `=` runes.
23+different situations. Hence the whole family of `=` runes.
27−### `=>` "tisgar"
27+## `=>` "tisgar"
29−`[%tsgr p=hoon q=hoon]`: compose two expressions.
29+Compose two expressions.
31−##### Produces
31+#### Syntax
33−the product of `q`, with the product of `p` taken as the subject.
33+Two arguments, fixed.
35−##### Syntax
35+Tall form:
37−Regular: **2-fixed**.
37+```hoon
60+the product of `q`, with the product of `p` taken as the subject.
39−##### Examples
62+#### Examples
42> =>([a=1 b=2 c=3] b)
65> =>([a=1 b=2 c=3] b)
45> =>((add 2 4) [. .])
71> =>((add 2 4) [. .])
49−### `=|` "tisbar"
86+## `=|` "tisbar"
88+Combine a default type value ("bunt value") with the subject.
52−`[%tsbr p=spec q=hoon]`: combine a default type value with the subject.
114+[%tsbr p=spec q=hoon]
54−##### Expands to
117+#### Expands to
60−##### Syntax
123+#### Discussion
62−Regular: **2-fixed**.
125+The default (or 'bunt') value of `p` is pinned to the head of the subject.
126+Usually `p` includes a name for ease of reference.
64−##### Discussion
128+Speaking more loosely, `=|` usually "declares a variable" which is
129+"uninitialized," presumably because you'll set it in a loop or similar.
66−The default (or 'bunt') value of `p` is pinned to the head of the subject. Usually `p` includes a name for ease of reference.
131+#### Examples
68−Speaking more loosely, `=|` usually "declares a variable" which is "uninitialized," presumably because you'll set it in a loop or similar.
133+```
70−##### Examples
145+Change multiple legs in the subject.
149+Two arguments: the first a variable number of pairs, the second is fixed.
73−~zod:dojo> =foo |= a=@
160+
77−~zod:dojo> (foo 5)
164+=:(p1a p1b, p2a p2b, p3a p3b q)
81−### `=:` "tiscol"
167+Irregular form:
83−`[%tscl p=(list (pair wing hoon)) q=hoon]`: change multiple legs in the subject.
169+None.
85−##### Expands to
171+#### AST
88−=>(%_(. p) q)
174+[%tscl p=(list (pair wing hoon)) q=hoon]
91−##### Syntax
177+#### Expands to
93−Regular: **jogging**, then **1-fixed**.
179+```hoon
95−##### Discussion
183+#### Discussion
97This rune is like `=.`, but for modifying the values of multiple legs of the subject.
185This rune is like `=.`, but for modifying the values of multiple legs of the subject.
99−##### Examples
187+#### Examples
102−~zod:dojo> =+ a=[b=1 c=2]
190+> =+ a=[b=1 c=2]
103− =: c.a 4
191+ =: c.a 4
110−### `=,` "tiscom"
200+## `=,` "tiscom"
206+Two arguments, fixed.
112−`[%tscm p=hoon q=hoon]`: expose namespace
221+Irregular form:
114−`p` evaluates to a noun with some namespace. From within `q` you may access `p`'s names without a wing path (i.e., you can use face `b` rather than `b.p`). This is especially useful for calling arms from an imported library core or for calling arms from a stdlib core repeatedly.
223+None.
116−##### Syntax
225+#### AST
118−Regular: **2-fixed**.
227+```hoon
228+[%tscm p=hoon q=hoon]
233+`p` evaluates to a noun with some namespace. From within `q` you may access
234+`p`'s names without a wing path (i.e., you can use face `b` rather than `b.p`).
238+This is especially useful for calling arms from an imported library core or for
239+calling arms from a stdlib core repeatedly. For example, JSON reparsers like
240+`so:dejs:format` and `of:dejs:format` can be called as `so` and `of` after
120−##### Examples
247+#### Examples
122With an imported core:
249With an imported core:
125> (sum -7 --7)
252> (sum -7 --7)
127−[crash message]
254+dojo: hoon expression failed
129> (sum:si -7 --7)
256> (sum:si -7 --7)
@@ -142,26 +269,53 @@ With a dojo-defined face:
145−### `=.` "tisdot"
274+## `=.` "tisdot"
276+Change one leg in the subject.
147−`[%tsdt p=wing q=hoon r=hoon]`: change one leg in the subject.
278+#### Syntax
149−##### Expands to
280+Three arguments, fixed.
152−=>(%_(. p q) r)
285+=. p q
155−##### Syntax
289+Wide form:
157−Regular: **3-fixed**.
291+```hoon
159−##### Discussion
295+Irregular form:
161−Technically the `=.` rune doesn't change the subject. It creates
297+None.
162−a new subject just like the old one except for a changed value at `p`. Note that the mutation uses [`%_` ("cencab")](/docs/hoon/reference/rune/cen#cencab), so the type at `p` doesn't change. Trying to change the value type results in a `nest-fail`.
302+[%tsdt p=wing q=hoon r=hoon]
313+Technically the `=.` rune doesn't change the subject. It creates a new subject
314+just like the old one except for a changed value at `p`. Note that the mutation
315+uses [`%_` ("cencab")](/docs/hoon/reference/rune/cen#cencab), so the type at `p`
316+doesn't change. Trying to change the value type results in a `nest-fail`.
164−##### Examples
318+#### Examples
167> =+ a=[b=1 c=2]
321> =+ a=[b=1 c=2]
@@ -178,62 +332,117 @@ a new subject just like the old one except for a changed value at `p`. Note tha
181−### `=-` "tishep"
335+---
183−`[%tshp p=hoon q=hoon]`: combine a new noun with the subject, inverted.
337+## `=-` "tishep"
185−##### Expands to
339+Combine a new noun with the subject, inverted.
343+Two arguments, fixed.
188−=>([q .] p)
355+=-(p q)
191−##### Syntax
358+Irregular form:
193−Regular: **2-fixed**.
360+None.
195−##### Discussion
362+#### AST
365+[%tshp p=hoon q=hoon]
376+`=-` is just like `=+` but its subexpressions are reversed. `=-` looks better
197−`=-` is just like `=+` but its subexpressions are reversed. `=-` looks better than `=+` when the expression you're pinning to the subject is much smaller than the expression that uses it.
377+than `=+` when the expression you're pinning to the subject is much smaller than
378+the expression that uses it.
199−##### Examples
380+#### Examples
202−~zod:dojo> =foo |= a=@
383+> =foo |= a=@
204− =- (add a b c)
385+ =- (add a b c)
206−~zod:dojo> (foo 5)
387+> (foo 5)
210−### `=^` "tisket"
391+---
212−`[%tskt p=skin q=wing r=hoon s=hoon]`: pin the head of a pair; change
393+## `=^` "tisket"
215−##### Expands to
395+Pin the head of a pair; change a leg with the tail.
399+Four arguments, fixed.
218−=/(p -.r =.(q +.r s))
404+=^ p q
221−##### Syntax
409+Wide form:
223−Regular: **4-fixed**.
411+```hoon
225−##### Discussion
415+Irregular form:
422+[%tskt p=skin q=wing r=hoon s=hoon]
428+=/(p -.r =.(q +.r s))
433+`p` is a new name (possibly with type annotation, e.g., `a=@`) of a value to be
434+pinned to the subject. The value of `p` is the head of the product of `r`. `q`
227−`p` is a new name (possibly with type annotation, e.g., `a=@`) of a value to be pinned to the subject. The value of `p` is the head of the product of `r`. `q` is given the value of the tail of `r`'s product. Then `s` is evaluated against this new subject.
435+is given the value of the tail of `r`'s product. Then `s` is evaluated against
229We generally use `=^` when we have a state machine with a function, `r`, that
438We generally use `=^` when we have a state machine with a function, `r`, that
230produces a cell, whose head is a result and whose tail is a new
439produces a cell, whose head is a result and whose tail is a new
231−state. The head value is given a new name `p`, and the
440+state. The head value is given a new name `p`, and the
232tail is stuffed back into wherever we stored the old state, `q`.
441tail is stuffed back into wherever we stored the old state, `q`.
234This may also remind you of Haskell's State monad.
443This may also remind you of Haskell's State monad.
236−##### Examples
445+#### Examples
238The `og` core is a stateful pseudo-random number generator.
447The `og` core is a stateful pseudo-random number generator.
239We have to change the core state every time we generate a
448We have to change the core state every time we generate a
@@ -247,114 +456,235 @@ random number, so we use `=^`:
250−### `=<` "tisgal"
461+## `=<` "tisgal"
252−`[%tsgl p=hoon q=hoon]`: compose two expressions, inverted.
463+Compose two expressions, inverted.
254−##### Expands to
465+#### Syntax
260−##### Syntax
476+Wide form:
262−Regular: **2-fixed**.
478+```hoon
264−Irregular: `foo:baz` is `=<(foo baz)`.
482+Irregular form:
491+[%tsgl p=hoon q=hoon]
266−##### Discussion
500+#### Discussion
268`=<` is just `=>` backwards.
502`=<` is just `=>` backwards.
270−##### Examples
504+#### Examples
273−~zod:dojo> =<(b [a=1 b=2 c=3])
507+> =<(b [a=1 b=2 c=3])
276−~zod:dojo> =< b
510+> =< b
277− [a=1 b=2 c=3]
511+ [a=1 b=2 c=3]
280−~zod:dojo> b:[a=1 b=2 c=3]
514+> b:[a=1 b=2 c=3]
283−~zod:dojo> [. .]:(add 2 4)
517+> [. .]:(add 2 4)
287−### `=+` "tislus"
521+---
290−`[%tsls p=hoon q=hoon]`: combine a new noun with the subject.
525+Combine a new noun with the subject.
292−##### Expands to
527+#### Syntax
529+Two arguments, fixed.
298−##### Syntax
538+Wide form:
300−Regular: **2-fixed**.
540+```hoon
551+[%tsls p=hoon q=hoon]
302−##### Discussion
560+#### Discussion
304−The subject of the `=+` expression, call it `a`, becomes the cell `[p a]` for the evaluation of `q`. That is, `=+` 'pins a value', `p`, to the head of the subject.
562+The subject of the `=+` expression, call it `a`, becomes the cell `[p a]` for
563+the evaluation of `q`. That is, `=+` 'pins a value', `p`, to the head of the
306Loosely speaking, `=+` is the simplest way of "declaring a variable."
566Loosely speaking, `=+` is the simplest way of "declaring a variable."
308−##### Examples
568+#### Examples
577+> =+ [a='foo' b='bar'] a
310−### `=;` "tismic"
585+Combine a named noun with the subject, possibly with type annotation; inverted
312−`[%tsmc p=skin q=hoon r=hoon]`: combine a named noun with the subject, possibly with type annotation; inverted order.
588+#### Syntax
314−##### Expands to
590+Three arguments, fixed.
320−##### Syntax
600+Wide form:
322−Regular: **3-fixed**.
602+```hoon
324−##### Discussion
606+Irregular form:
326−`=;` is exactly like `=/` except that the order of its last two subexpressions is reversed.
608+None.
328−##### Examples
610+#### AST
613+[%tsmc p=skin q=hoon r=hoon]
624+`=;` is exactly like `=/` except that the order of its last two subexpressions
331−~zod:dojo> =foo |= a=@
630+> =foo |= a=@
333− =; c=@ :(add a b c)
633+ :(add a b c)
335−~zod:dojo> (foo 5)
635+> (foo 5)
339−### `=/` "tisfas"
641+## `=/` "tisfas"
643+Combine a named noun with the subject, possibly with type annotation.
647+Three arguments, fixed.
341−`[%tsfs p=skin q=hoon r=hoon]`: combine a named noun with the subject, possibly with type annotation.
665+None.
343−##### Expands to
667+#### AST
670+[%tsfs p=skin q=hoon r=hoon]
345−**if `p` is a name**, (e.g. `a`):
675+if `p` is a name, (e.g. `a`):
348=+(^=(p q) r)
678=+(^=(p q) r)
351−**if `p` is a name with a type** (e.g., `a=@`):
681+if `p` is a name with a type (e.g., `a=@`):
354=+(^-(p q) r)
684=+(^-(p q) r)
357−##### Desugaring
687+#### Desugaring
@@ -364,76 +694,139 @@ Regular: **3-fixed**.
367−##### Syntax
697+#### Discussion
369−Regular: **3-fixed**.
699+`p` can be either a name or a `name=type`. If it's just a name, `=/` ("tisfas")
700+"declares a type-inferred variable." If it has a type, `=/` "declares a
701+type-checked variable."
371−##### Discussion
703+#### Examples
373−`p` can be either a name or a name=type. If it's just a name,
705+```
374−`=/` ("tisfas") "declares a type-inferred variable." If it has a type, `=/`
706+> =/ a=@t 'hello' a
375−"declares a type-checked variable."
707+'hello'
377−##### Examples
709+> =/ x [1 2 3] x
380−~zod:dojo> =foo |= a=@
712+> =foo |= a=@
382− =/ c=@ 2
714+ =/ c=@ 2
383− :(add a b c)
715+ :(add a b c)
384−~zod:dojo> (foo 5)
716+> (foo 5)
388−### `=~` "tissig"
720+---
391−`[%tssg p=(list hoon)]`: compose many expressions.
724+Compose many expressions.
393−##### Produces
726+#### Syntax
395−The product of the chain composition.
728+Variable number of arguments.
397−##### Syntax
730+Tall form:
399−Regular: **running**.
732+```hoon
401−##### Examples
740+Wide form:
753+[%tssg p=(list hoon)]
758+The product of the chain composition.
404−~zod:dojo> =~ [sub (mul 3 20) (add 10 20)]
771+> =~ [sub (mul 3 20) (add 10 20)]
410−~zod:dojo> =foo =| n=@
777+> =foo =| n=@
411− =< =~ increment
778+ =< =~ increment
412− increment
779+ increment
413− increment
780+ increment
417− ++ increment
784+ ++ increment
418− ..increment(n +(n))
785+ ..increment(n +(n))
420−~zod:dojo> foo
787+> foo
424−### `=*` "tistar" {#tistar}
791+---
426−`[%tstr p=term q=hoon r=hoon]`: define a deferred expression.
793+## `=*` "tistar" {#tistar}
428−##### Produces
795+Define a deferred expression.
430−`r`, compiled with a subject in which `p` is a deferred expression for `q`.
797+#### Syntax
799+Three arguments, fixed.
432−##### Syntax
817+None.
434−Regular: **3-fixed**.
819+#### AST
822+[%tstr p=term q=hoon r=hoon]
827+`r`, compiled with a subject in which `p` is a deferred expression for `q`.
436−##### Discussion
829+#### Discussion
438`=*` assigns a name to an expression that will be evaluated in each place the
831`=*` assigns a name to an expression that will be evaluated in each place the
439name is dereferenced. This allows you to "write" through it to the original
832name is dereferenced. This allows you to "write" through it to the original
@@ -443,47 +836,81 @@ calculated every time you use `p`.
443This rune has some similarities with macros, and some similarities with aliases,
836This rune has some similarities with macros, and some similarities with aliases,
444but it is not really either.
837but it is not really either.
839+This rune is commonly used to give a Gall agent's state the name `state` like:
845+This lets you reference the whole `state` while also being able to reference its
846+individual elements like `foo` and `bar`, without having to do `foo.state`,
446−##### Examples
849+#### Examples
463−### `=?` "tiswut"
866+## `=?` "tiswut"
868+Conditionally change one leg in the subject.
465−`[$tswt p=wing q=hoon r=hoon s=hoon]`: conditionally change one leg in the subject.
872+Four arguments, fixed.
467−##### Expands to
874+Tall form:
470−=. p ?:(q r p)
877+=? p q
474−##### Syntax
882+Wide form:
895+[%tswt p=wing q=hoon r=hoon s=hoon]
476−Regular: **4-fixed**.
900+```hoon
478−##### Discussion
905+#### Discussion
480Use `=?` to replace the value of leg `p` with `r` on condition `q`. As
907Use `=?` to replace the value of leg `p` with `r` on condition `q`. As
481usual, we are not actually mutating the subject, just creating
908usual, we are not actually mutating the subject, just creating
482−a new subject with a changed value. The change in value includes a
909+a new subject with a changed value. The change in value includes a
483type check against the old subject; the type of `r` must nest under
910type check against the old subject; the type of `r` must nest under
484the type of `p`.
911the type of `p`.
486−##### Examples
913+#### Examples