on master help sign in
Various fixes and improvements.
35eeb23C. Guy Yarvin
docs/programming/hoon/catalog/col-cell/cab-scon.md+16−21
@@ -1,29 +1,24 @@
1−# `:scon`, `:_`, "colcab", `{$scon p/twig q/twig}`
1+---
2+sort: 6
3+---
2
4
3−Inverted tuple of `p` `q`.
5+# `:scon, :_, "colcab", {$scon p/twig q/twig}`
4
6
5−Produces: a cell of `[q p]`. Exists for code readability and organization. See the backstep convention.
7+Construct a cell, inverted.
6
8
7−Regular form: *2-fixed*
9+## Expands to
8
10
9−Examples:
11+```
12+:cons(q p)
13+```
10
14
11− ~zod:dojo> :_(1 2)
15+## Syntax
12− [2 1]
13
16
14−A simple example. `:_` produces the cell of any two twigs, but in
17+Regular: *2-fixed*.
15−reverse order.
16
18
17− ~zod:dojo> `tape`:_(~ 'a')
19+## Examples
18− "a"
19
20
20−Since a `++tape` is a null-terminated list of characters, casting
21+```
21−the result of `:_(~ 'a')` to a `tape` produces `"a"`.
22−
23− /~zod:dojo>
22+~zod:dojo> :_(1 2)
24− :_ (add 2 2)
25− |- (div 4 2)
26− [2 4]
23+[2 1]
27−
24+```
28−Most commonly `:_` helps to organize code, allowing you to produce a
29−cell from nested computation.
docs/programming/hoon/catalog/col-cell/hep-cons.md+25−49
@@ -1,66 +1,42 @@
1−# `:cons`, `:-`, "colhep", `{$cons p/twig q/twig}`
1+---
2+sort: 1
3+---
2
4
3−*Construct a cell (2-tuple*).
5+# `:cons, :-, "colhep", {$cons p/twig q/twig}`
4
6
5−Syntax: *2-fixed*.
7+Construct a cell (2-tuple).
6
8
7−The product: the cell of `p` and `q`, each compiled against
9+## Produces
8−the subject.
9
10
10−Irregular forms:
11+The cell of `p` and `q`.
11
12
12−```
13+## Syntax
13−[a b] :-(a b)
14−1^2^3 [1 2 3]
15−a+1 [%a 1]
16−`1 [~ 1]
17−[1 2]~ [[1 2] ~]
18−```
19−
20−Examples:
21−
22− ~zod:dojo> :-(1 2)
23− [1 2]
24− ~zod:dojo> :- 'a'
25− %b
26− ['a' %b]
27
14
28−This is the most straightforward case of `:-`, producing a cell of
15+Regular: *2-fixed*.
29−static data in either tall or wide form.
30
16
31− /~zod:dojo>
17+Irregular: `[a b]` is `:cons(a b)`.
32− :- (add 2 2)
33− |- (div 4 2)
34− [4 2]
35
18
36−Most commonly `:-` helps to organize code, allowing you to produce a
19+Irregular: `[a b c]` is `[a [b c]]`.
37−cell from nested computation.
38
20
39−Some obscure `:-` irregular forms
21+Irregular: `a^b^c` is `[a b c]`.
40−==================================
41
22
42−### Infix `^`
23+Irregular: `a+b` is `[%a b]`.
43
24
44− ~zod:dojo> 1^2^3
25+Irregular: `\`a` is `[~ a]`.
45− [1 2 3]
46
26
47−`a^b` is equivalent to `:- a b`
27+Irregular: `~[a b]` is `[a b ~]`.
48
28
49−### Infix `/`
29+Irregular: `[a b c]~` is `[[a b c] ~]`.
50
30
51− ~zod:dojo> a/1
31+## Discussion
52− [%a 1]
53− ~zod:dojo> a/'twig'
54− [%a 'twig']
55
32
56−Like `^`, but first item must be a `++term`, and is cubed. Used to construct `path`s and frond.
33+Hoon twigs actually use the same "autocons" pattern as Nock
34+formulas. If you're assembling twigs (which usually only the
35+compiler does), `[a b]` is the same as `[%cons a b]`.
57
36
58−### Prefix `` ` ``, postfix `~`
37+## Examples
59
38
60− ~zod:dojo> ````20
39+```
61− [~ ~ ~ ~ 20]
62− ~zod:dojo> [42 30]~
40+~zod:dojo> :-(1 2)
63− [[42 30] ~]
41+[1 2]
64−
42+```
65−Complimenting each other, these construct pairs with `~` in the head and
66−`tail` respectively. Multiple postfix `~` do not work for unknown reasons.
docs/programming/hoon/catalog/col-cell/ket-conq.md+20−20
@@ -1,28 +1,28 @@
1−# `:conq`, `:^`, "colket", `{$conq p/twig q/twig r/twig s/twig}`
1+---
2+sort: 3
3+---
2
4
3−Tuple of four.
5+# `:conq, :^, "colket", {$conq p/twig q/twig r/twig s/twig}`
4
6
5−Produces: the tuple of `[p q r s]`.
7+Construct a quadruple (4-tuple).
6
8
7−Regular form: *4-fixed*
9+## Expands to
8
10
9−Examples
11+```
12+:cons(p :cons(q :cons(r s)))
13+```
10
14
11− /~zod:dojo> :^(1 2 3 4)
15+## Syntax
12− [1 2 3 4]
13− /~zod:dojo> :^ 5 6
14− 7
15− 8
16− [5 6 7 8]
17
16
18−These are the most straightforward cases of `:^`, producing a tuple of four
17+Regular: *4-fixed*.
19−values in both tall and wide forms respectively.
20
18
21− /~zod:dojo>
19+## Examples
22− :^ (add 2 4) (add 2 6)
23− |- (div 4 2)
24− ~
25− [6 8 2 ~]
26
20
27−Most commonly `:^` helps to organize code, allowing you to produce a
21+```
28−cell from nested computation.
22+/~zod:dojo> :^(1 2 3 4)
23+[1 2 3 4]
24+/~zod:dojo> :^ 5 6
25+ 7
26+ 8
27+[5 6 7 8]
28+```
docs/programming/hoon/catalog/col-cell/lus-cont.md+20−22
@@ -1,30 +1,28 @@
1−# `:cont`, `:+`, "collus", `{$cont p/twig q/twig r/twig}`
1+---
2−===========
2+sort: 2
3+---
3
4
4−Tuple of 3.
5+# `:cont, :+, "collus", {$cont p/twig q/twig r/twig}`
5
6
6−Produces: the tuple of `p`, `q`, and `r`.
7+Construct a triple (3-tuple).
7
8
8−Regular form:
9+## Expands to:
9
10
10−*3-fixed*
11+```
12+:cons(p :cons(q r))
13+```
11
14
12−Examples:
15+## Syntax
13
16
14− /~zod:dojo> :+ 1
17+Regular: *3-fixed*.
15− 2
16− 3
17− [1 2 3]
18− /~zod:dojo> :+(%a ~ 'b')
19− [%a ~ 'b']
20
18
21−This is the most straightforward case of `:+`, producing a tuple of three
19+## Examples
22−values in both tall and wide form.
23
20
21+```
24− /~zod:dojo>
22+/~zod:dojo> :+ 1
25− :+ (add 2 4) (add 2 6)
23+ 2
26− |- (div 4 2)
24+ 3
27− [6 8 2]
25+[1 2 3]
28−
26+/~zod:dojo> :+(%a ~ 'b')
29−Most commonly `:+` helps to organize code, allowing you to produce a
27+[%a ~ 'b']
30−cell from nested computation.
28+```
docs/programming/hoon/catalog/col-cell/sig-conl.md+33−40
@@ -1,40 +1,33 @@
1+---
2+sort: 5
3+---
4+
1−# `:conl`, `:~`, "colsig", `{$conl p/(list twig)}`
5+# `:conl, :~, "colsig", {$conl p/(list seed)}`
2−===========
6+
3−
7+Construct a null-terminated list.
4−Null-terminated tuple of n elements.
8+
5−
9+## Expands to
6−Produces: tuple of input elements. Closed with `==` in tall form.
10+
7−
11+```
12+|-(?~(p ~ :cons(i.p $(p t.p))))
13+```
14+
15+## Syntax
16+
8−Regular form: *running*
17+Regular: *running*.
9−
18+
10−Examples:
19+## Examples
11−
20+
21+```
12− /~zod:dojo> :~(5 3 4 2 1)
22+~zod:dojo> :~(5 3 4 2 1)
13− [5 3 4 2 1 ~]
23+[5 3 4 2 1 ~]
14− /~zod:dojo> ~[5 3 4 2 1]
24+~zod:dojo> ~[5 3 4 2 1]
15− [5 3 4 2 1 ~]
25+[5 3 4 2 1 ~]
16− /~zod:dojo> :~ 5
26+~zod:dojo> :~ 5
17− 3
27+ 3
18− 4
28+ 4
19− 2
29+ 2
20− 1
30+ 1
21− ==
31+ ==
22− [5 3 4 2 1 ~]
32+[5 3 4 2 1 ~]
23−
33+```
24−This is the most straightforward case of `:~`, producing a tuple in wide, irregular and tall form.
25−
26− /~zod:dojo> %- flop
27− %- limo
28− :~ 5
29− 3
30− 4
31− 2
32− 1
33− ==
34− ~[1 2 4 3 5]
35−
36−In this example we use `%-` to pass the results of our previous example
37−to `++limo`, which creates a `++list`, and `++flop`, which
38−reverses its order. This example shows how `:~` is commonly useful.
39−Null-terminated tuples are easily converted to lists, which are
40−frequently encountered in hoon.
docs/programming/hoon/catalog/col-cell/tar-conp.md+30−23
@@ -1,29 +1,36 @@
1−# `:conp`, `:*`, "coltar", {$conp p/(list twig)}
1+---
2+sort: 4
3+---
2
4
3−Tuple of n elements.
5+# `:conp, :*, "coltar" {$conp p/(list twig)}`
4
6
5−Produces: tuple of input elements. Closed with `==`.
7+Construct an n-tuple.
6
8
7−Regular form: *running*
9+## Expands to
8
10
9−Examples
11+```
10−--------
12+|-(?~(p !! ?~(t.p i.p :cons(i.p $(p t.p)))))
13+```
11
14
12− /~zod:dojo> :*(5 3 4 1 4 9 0 ~ 'a')
15+## Syntax
13− [5 3 4 1 4 9 0 ~ 'a']
14− /~zod:dojo> [5 3 4 1 4 9 0 ~ 'a']
15− [5 3 4 1 4 9 0 ~ 'a']
16− /~zod:dojo> :* 5
17− 3
18− 4
19− 1
20− 4
21− 9
22− 0
23− ~
24− 'a'
25− ==
26− [5 3 4 1 4 9 0 ~ 'a']
27
16
28−This is the most straightforward case of `:*`, producing tuples of n
17+Regular: *running*.
29−values in wide, irregular and tall forms.
18+
19+## Examples
20+```
21+/~zod:dojo> :*(5 3 4 1 4 9 0 ~ 'a')
22+[5 3 4 1 4 9 0 ~ 'a']
23+/~zod:dojo> [5 3 4 1 4 9 0 ~ 'a']
24+[5 3 4 1 4 9 0 ~ 'a']
25+/~zod:dojo> :* 5
26+ 3
27+ 4
28+ 1
29+ 4
30+ 9
31+ 0
32+ ~
33+ 'a'
34+ ==
35+[5 3 4 1 4 9 0 ~ 'a']
36+```
docs/programming/hoon/catalog/ket-cast/bar-iron.md+33−20
@@ -1,26 +1,39 @@
1−# `:iron`, `^|`, "ketbar", `{$iron p/twig}`
1+---
2+sort: 5
3+---
2
4
3−Make core context unreadable.
5+# `:iron ^| "ketbar" {$iron p/seed}`
4
6
5−Converts an %gold core `p` to an %iron core. Useful in preventing type
7+Convert a gold core to a contravariant core (write-only sample).
6−fails when replacing one core with one context with another core with a
7−different context.
8
8
9−Regular form: *1-fixed*
9+## Produces
10
10
11−Examples:
11+`p` as an iron core; crash if not a gold core.
12
12
13− /~zod:dojo> =cor |= a/@
13+## Syntax
14− +(a)
14+
15− new var %cor
15+Regular: *1-fixed*.
16+
17+## Discussion
18+
19+An iron core is an opaque function (gate or door).
20+
21+Theorem: if span `x` nests within span `a`, and span `y` nests
22+within span `b`, a core accepting `b` and producing `x` nests
23+within a iron core accepting `y` and producing `a`.
24+
25+Informally, a function fits an interface if the function has a
26+more specific result and/or a less specific argument than the
27+interface.
28+
29+## Examples
30+
31+The prettyprinter shows the core metal (`.` gold, `|` iron):
32+
33+```
16− /~zod:dojo> +<.cor
34+~zod:dojo> |=(@ 1)
17− a=0
35+<1.gcq [@ @n <250.yur 41.wda 374.hzt 100.kzl 1.ypj %151>]>
18− /~zod:dojo> =iro ^|(cor)
36+~zod:dojo> ^|(|=(@ 1))
19− new var %iro
37+<1|gcq [@ @n <250.yur 41.wda 374.hzt 100.kzl 1.ypj %151>]>
20− /~zod:dojo> +<.iro
38+```
21− ! -axis.6
22− ! peek-park
23− ! exit
24
39
25−Here we crete a simple gate and assign it to the shell variable `cor`.
26−We can examine the sample of `cor` with `+<` (the head of the tail) to produce `a=0`. Assigning a new shell variable, `iro` as the `^|` of `cor` we can no longer peek in to its subject.
docs/programming/hoon/catalog/ket-cast/hep-cast.md+31−28
@@ -1,38 +1,41 @@
1−# `:cast`, `^-`, "kethep", `{$cast p/twig q/twig}`
1+---
2+sort: 2
3+---
2
4
3−Cast.
5+# `:cast ^- "kethep" {$cast p/moss q/seed}`
4
6
5−Casts `q` to the span of `p`. The same as `^+`, except for that `q` is actually cast to the bunt of `q` (`$,(q)`). The easiest way to make a basic cast; used when you already have already created a validator function (mold) for a span.
7+Cast by construction (mold).
6
8
7−Regular form: *2-fixed*
9+## Expands to
8
10
9−Irregular form:
11+```
12+:like(:bunt(p) q)
13+```
10
14
15+## Syntax
11
16
12− `p`q ^-(p q)
17+Regular: *2-fixed*
13
18
19+## Discussion
14
20
15−Examples:
21+It's a good practice to put a `:cast` at the top of every arm
22+(including gates, loops, etc). This cast is strictly necessary
23+only in the presence of head recursion (otherwise you'll get a
24+`rest-loop` error, or if you really screw up spectacularly an
25+infinite loop in the compiler).
16
26
17− ~zod:dojo> (add 90 7)
27+## Examples
18− 97
19− ~zod:dojo> `@t`(add 90 7)
20− 'a'
21− ~zod:dojo> ^-(@t (add 90 7))
22− 'a'
23
28
24−Here we see a straightforward use of `^-` in both irregular and wide
29+``
25−forms, simply casting an atom to a `@t`. `97` is the ASCII code for
30+~zod:dojo> (add 90 7)
31+97
32+~zod:dojo> `@t`(add 90 7)
33+'a'
34+~zod:dojo> ^-(@t (add 90 7))
26−`'a'`.
35+'a'
27−
28− /~zod:dojo> =cor |= a/@
36+/~zod:dojo> =foo |= a/@tas
29− ^- (unit @ta)
37+ ^- (unit @ta)
30− [~ u=a]
38+ `a
31− new var %cor
32− /~zod:dojo> (cor 97)
39+/~zod:dojo> (foo 97)
33− [~ ~.a]
40+[~ ~.a]
34−
41+```
35−In this case we see a very common use of `^-`, at the top of a function.
36−This pattern is considered good hoon style for two reasons: it gives the
37−reader a clear pattern for understanding what your code produces, and it
38−helps ensure type-safety.
docs/programming/hoon/catalog/ket-cast/lus-like.md+25−41
@@ -1,41 +1,25 @@
1+---
2+sort: 1
3+---
4+
1−# `:like`, `^+`, "ketlus", `{$like p/twig q/twig}`
5+# `:like ^+ "ketlus" {$like p/seed q/seed}`
2−
6+
3−Cast `q` to an unbunted `p`.
7+Cast by example (seed).
4−
8+
5−Casts `q` to the type of `p`, verifying that it contains
9+## Produces
6−the type of `q`. Similar to `^+`, but doesn't bunt `p`. Used to
10+
7−cast to types that have previously been made into validator
11+The value of `p` with the span of `q`, if the span of `p` nests
8−functions (clams) with `$,`. For example, the arguments to a `|=` are
12+within the span of `q`. Otherwise, `nest-fail`.
9−automatically bunted with a `=|`, so `^+` is used. Most often we use `^+` to cast when our type is already defined by something inside our context.
13+
10−
14+## Syntax
15+
11−Regular form: *2 fixed*
16+Regular: *2-fixed*.
12−
17+
18+Irregular: `\`_foo\`bar` is `:like(foo bar)`.
19+
13−Examples:
20+## Examples
14−
21+
22+```
15− ~zod:dojo> (add 90 7)
23+~zod:dojo> :like('text' 97)
16− 97
17− ~zod:dojo> ^+('any text' (add 90 7))
18− 'a'
24+'a'
19−
25+```
20−Here we use a '++cord' (which could be any cord), `'any text'` to cast our
21−result to a cord.
22−
23− /~zod:dojo> =cor |= a/{q/@ta r/@ s/@}
24− [(cat 3 'new' q.a) (add r.a s.a) (sub r.a s.a)]
25− new var %cor
26− /~zod:dojo> (cor 'start' 6 3)
27− [8.390.876.208.525.960.558 9 3]
28− /~zod:dojo> =cor |= a/[q/@ta r/@ s/@]
29− ^+ a
30− [(cat 3 'new' q.a) (add r.a s.a) (sub r.a s.a)]
31− changed %cor
32− /~zod:dojo> (cor 'start' 6 3)
33− [q=~.newstart r=9 s=3]
34−
35−In this example we create a gate `cor` and lightly manipulate the tuple
36−it takes as a sample: we prepend `'new'` to its first member, produce
37−the sum of the latter two as the second, and the differene as the third.
38−
39−In the first call you can see that our type information is lost, and we
40−produce our cord as an atom. By adding a `^+ a` we cast the result to
41−our input, and type information is retained.
docs/programming/hoon/catalog/ket-cast/pam-zinc.md−17
@@ -1,17 +0,0 @@
1−# `:zinc`, `^&`, "ketpam", `{$zinc p/twig}`
2−
3−Convert `%gold` to `%zinc`.
4−
5−Converts a `%gold` core `p` into a `%zinc` core.
6−
7−Examples:
8−
9− ~zod:dojo> |=(@ 1)
10− < 1.odf
11− {@ {our/@p now/@da eny/@uvI} $~ <282.ucw 42.juj 402.arm 110.jyx 1.ztu $151>}
12− >
13− ~zod:dojo> ^&(|=(@ 1))
14− < 1&odf
15− {@ {our/@p now/@da eny/@uvI} $~ <282.ucw 42.juj 402.arm 110.jyx 1.ztu $151>}
16− >
17−
docs/programming/hoon/catalog/ket-cast/tis-name.md+24−18
@@ -1,26 +1,32 @@
1−# `:name`, `^=`, "kettis", `{$name p/toga q/twig}`
1+---
2+sort: 3
3+---
2
4
3−Wraps a variable name around a value.
5+# `:name ^= "kettis" {$name p/toga q/seed}`
4
6
5−`^=`, `kettis`, `[%ktts p=toga q=twig]` is a natural rune that wraps `q`
7+Name a value.
6−in the `++toga` `p`. `^=` is most commonly used for assignment,
7−adding one or more names to values.
8
8
9−Regular form: *2-fixed*
9+## Produces
10
10
11−Examples:
11+If `p` is a term, the product `q` with span `[%face p q]`. `p`
12+may also be a tuple of terms, or a term-toga pair; the span of
13+`q` must divide evenly into cells to match it.
12
14
13− ~zod:dojo> a=1
15+## Syntax
14− a=1
15− ~zod:dojo> ^= a
16− 1
17− a=1
18
16
19−In this straightforward example we see the irregular and tall forms of
17+Regular: *2-fixed*.
20−`^=`, both of which assign `a` to be `1`.
21
18
22− ~zod:dojo> [b ~ c]=[1 2 3 4]
19+Irregular: `foo=bar` is `:name(foo bar)`.
23− [b=1 2 c=[3 4]]
24
20
25−Here we see multiple names being applied at once, using the irregular
21+## Examples
26−form of `^=`.
22+```
23+~zod:dojo> a=1
24+a=1
25+~zod:dojo> ^= a
26+ 1
27+a=1
28+~zod:dojo> [b c d]=[1 2 3 4]
29+[b=1 c=2 d=[3 4]]
30+~zod:dojo> [b c d=[x y]]=[1 2 3 4]
31+[b=1 c=2 d=[x=3 y4]]
32+```
docs/programming/hoon/catalog/ket-cast/wut-lead.md+31−9
@@ -1,15 +1,37 @@
1−# `:lead`, `^?` "ketwut", `{$lead p/twig}`
1+---
2+sort: 4
3+---
2
4
3−Convert core with unreadable sample to have unreadable sample and context.
5+# `:lead ^? "ketwut" {$lead p/seed}`
4
6
5−Converts a %gold core `p` to a %lead core.
7+Convert any core to a bivariant core (opaque payload).
6
8
7−Regular form: *1-fixed*
9+## Produces
8
10
11+`p` as a lead core; crash if not a core.
9
12
13+## Syntax
14+
15+Regular: *1-fixed*.
16+
17+## Discussion
18+
19+A lead core is an opaque generator.
20+
21+Theorem: if span `x` nests within span `a`, a lead core producing
22+`x` nests within a lead core producing `a`.
23+
24+Informally, a more specific generator can be used as a less
25+specific generator.
26+
10−Examples:
27+## Examples
28+
29+The prettyprinter shows the core metal (`.` gold, `?` lead):
30+
31+```
32+~zod:dojo> |=(@ 1)
33+<1.gcq [@ @n <250.yur 41.wda 374.hzt 100.kzl 1.ypj %151>]>
34+~zod:dojo> ^?(|=(@ 1))
35+<1?gcq [@ @n <250.yur 41.wda 374.hzt 100.kzl 1.ypj %151>]>
36+```
11
37
12− ~zod:dojo> |=(@ 1)
13− <1.gcq [@ @n <250.yur 41.wda 374.hzt 100.kzl 1.ypj %164>]>
14− ~zod:dojo> ^?(|=(@ 1))
15− <1?gcq [@ @n <250.yur 41.wda 374.hzt 100.kzl 1.ypj %164>]>
docs/programming/hoon/catalog/sem-make/col-wad.md+21−24
@@ -1,33 +1,30 @@
1−# ``, `;:`, "semcol" `{$wad p/twig q/(list twig)}`
1+---
2+sort: 3
3+---
2
4
3−Fold over tuple.
5+# `:wad ;: "semcol" {$wad p/seed q/(list seed)}`
4
6
5−Apply a binary function `p` to a tuple `q` with n elements. Similar to folding over the tuple `q`.
7+Call binary function as n-ary function.
6
8
7−Regular form: *running*
9+## Expands to
8
10
9−Irregular form:
11+```
12+|-(?~(q !! ?~(t.q !! ?~(t.t.q :call(p i.q i.t.q) :call(p i.q $(q t.q))))))
13+```
10
14
11−`:(p i.q i.t.q i.t.t.q) ;:(p i.q i.t.q i.t.t.q)`
15+## Syntax
12
16
13−Examples:
17+Regular: *1-fixed*, then *running*.
14
18
15− ~zod:dojo> (add 3 (add 4 5))
19+Irregular: `:(add a b c)` is `;:(add a b c)`.
16− 12
17− ~zod:dojo> ;:(add 3 4 5)
18− 12
19− ~zod:dojo> :(add 3 4 5)
20− 12
21
20
22−Here we see how `;:` is equivalent to nesting our calls to the binary
21+## Examples
23−gate `++add`.
24
22
25− ~zod:dojo> :(weld "foo" "bar" "baz")
23+```
26− ~[~~f ~~o ~~o ~~b ~~a ~~r ~~b ~~a ~~z]
24+~zod:dojo> (add 3 (add 4 5))
27− ~zod:dojo> `tape`:(weld "foo" "bar" "baz")
25+12
28− "foobarbaz"
26+~zod:dojo> ;:(add 3 4 5)
29− ~zod:dojo> `tape`(weld "foo" (weld "bar" "baz"))
27+12
30− "foobarbaz"
28+~zod:dojo> :(add 3 4 5)
31−
29+12
32−Following on from our previous example, using `;:` with `++weld` is
30+```
33−convenient for concatenating multiple strings.
docs/programming/hoon/catalog/sem-make/fas-nub.md+14−11
@@ -1,16 +1,19 @@
1−`:/ colfas`
1+---
2−===========
2+sort: 4
3+---
3
4
4−String to XML XX
5+# `:nub ;/ "semfas" {$nub p/seed}`
5
6
6−`:/`, `colfas`, is a synthetic rune that produces `[%$ [%$ p ~] ~]`,
7+Tape as XML element.
7−i.e., `[0 [0 p 0] 0]`.
8
8
9−Examples:
9+## Expands to
10
10
11− ~zod/try=> :/(20)
11+```
12− [[%~. [%~. 20] ~] ~]
12+[%$ [%$ p ~] ~]
13− ~zod/try=> :/(add 2 2)
13+```
14− [[%~. [%~. 4] ~] ~]
15
14
16−Wraps `++twig` in `[%$ [%$ .] ~]~`, used for interpolation.
15+## Examples
16+```
17+~zod/try=> :/("foo"
18+[[%$ [%$ "foo] ~] ~]
19+```
docs/programming/hoon/catalog/sem-make/sem-fry.md+44−14
@@ -1,18 +1,48 @@
1−# `:fry`, `;;`, "semsem" `{$fry p/twig q/twig}`
1+---
2+sort: 1
3+---
2
4
3−Fixpoint.
5+# `:fry ;; "semsem" {$fry p/moss q/seed}`
4
6
5−Slams `q` through gate `p`, asserting that the
7+Normalize with a mold, asserting fixpoint.
6−resulting noun is equal to `.=` the original, and produces it.
7
8
8−Examples: XX Review closely
9+## Expands to
9
10
11+```
12+:pin(:name(a (p q)) :sure(=(a (p a)) a))
13+```
14+
15+## Syntax
16+
17+Regular: *2-fixed*.
18+
19+## Examples
20+
21+Fails because of auras:
22+
23+```
10− ~zod:dojo> ^-(tape ~[97 98 99])
24+~zod:dojo> ^-(tape ~[97 98 99])
11− ! type-fail
25+! nest-fail
12− ! exit
26+! exit
27+```
28+
29+Succeeds because molds don't care about auras:
30+
31+```
13− ~zod:dojo> ;;(tape ~[97 98 99])
32+~zod:dojo> ;;(tape ~[97 98 99])
14− "abc"
33+"abc"
34+```
35+
36+Succeeds because the mold normalizes:
37+
38+```
15− ~zod:dojo> (tape [50 51 52])
39+~zod:dojo> (tape [50 51 52])
16− "23"
40+"23"
41+```
42+
43+Fails because not a fixpoint:
44+
45+```
17− ~zod:dojo> ;;(tape [50 51 52])
46+~zod:dojo> ;;(tape [50 51 52])
18− ! exit
47+! exit
48+```
docs/programming/hoon/catalog/sem-make/sig-dip.md+62−133
@@ -1,133 +1,62 @@
1+---
2+sort: 2
3+---
4+
1−# `:dip`, `;~`, "semsig" `{$dip p/twig q/(list twig)}`
5+# `:dip`, `;~`, "semsig" `{$dip p/seed q/(list seed)}`
2−
6+
3−Monad composer.
7+Glue a pipeline together with a product-sample adapter.
4−
8+
5−Composes a list of functions `p` and `q` under a monad. `q` can be 1 or more functions.
9+## Produces
6−
10+
11+The gates in `q` connected together using the gate `p`, which
12+transforms a `q` product and a `q` gate into a `q` sample.
13+
14+## Discussion
15+
16+Apparently `:dip` is a "Kleisli arrow." Whatevs. It's also
17+a close cousin of the infamous "monad." Don't let that bother
18+you either. Hoon doesn't know anything about category theory,
19+so you don't need to either.
20+
21+`:dip` is often used in parsers, but is not only for parsers.
22+
23+## Syntax
24+
7−Regular form: 1-fixed, `q` is *running*
25+Regular: *1-fixed*, then *running*.
8−
26+
9−Examples:
27+## Examples
10−
28+
29+A simple "parser." `trip` converts a `cord` (atomic string) to
30+a `tape` (linked string).
31+
32+```
11− ~zod:dojo> =cmp |=([a=tape b=$+(char tape)] `tape`?~(a ~ (weld (b i.a) t.a)))
33+~zod:dojo> =cmp |=({a/tape b/$-(char tape)] `tape`?~(a ~ (weld (b i.a) t.a)))
12− ~zod:dojo> ;~(cmp trip)
34+~zod:dojo> ;~(cmp trip)
13− <1.xef [a=@ <374.hzt 100.kzl 1.ypj %164>]>
35+<1.xef [a=@ <374.hzt 100.kzl 1.ypj %164>]>
14− ~zod:dojo> (;~(cmp trip) 'a')
36+~zod:dojo> (;~(cmp trip) 'a')
15− "a"
37+"a"
16−
38+```
17−`;~` accepts a composer and a nonempty list of functions; at one gate, the
39+
18−composer is ignored, and the gate applied directly.
40+With just one gate in the pipeline `q`, the glue `p` is unused:
19−
41+
42+```
20− ~zod:dojo> (;~(cmp trip |=(a=@ ~[a a])) 'a')
43+~zod:dojo> (;~(cmp trip |=(a/@ ~[a a])) 'a')
21− "aa"
44+"aa"
22− ~zod:dojo> (;~(cmp trip |=(a=@ ~[a a])) '')
45+~zod:dojo> (;~(cmp trip |=(a/@ ~[a a])) '')
23− ""
46+""
24−
47+```
48+
25−For multiple gates, `;~` uses the composer to connect the gates in
49+But for multiple gates, we need it to connect the pipeline:
26−order.
50+
27−
51+```
28− ~zod:dojo> (;~(cmp trip ;~(cmp |=(a=@ ~[a a]) |=(a=@ <(dec a)>))) 'b')
52+~zod:dojo> (;~(cmp trip ;~(cmp |=(a/@ ~[a a]) |=(a/@ <(dec a)>))) 'b')
29− "97b"
53+"97b"
30− ~zod:dojo> (;~(cmp trip |=(a=@ ~[a a]) |=(a=@ <(dec a)>)) 'b')
54+~zod:dojo> (;~(cmp trip |=(a/@ ~[a a]) |=(a/@ <(dec a)>)) 'b')
31− "97b"
55+"97b"
32− ~zod:dojo> (;~(cmp trip |=(a=@ ~[a a]) |=(a=@ <(dec a)>)) '')
56+~zod:dojo> (;~(cmp trip |=(a/@ ~[a a]) |=(a/@ <(dec a)>)) '')
33− ""
57+""
34− ~zod:dojo> (;~(cmp trip |=(a=@ ~[a a]) |=(a=@ <(dec a)>)) 'a')
58+~zod:dojo> (;~(cmp trip |=(a/@ ~[a a]) |=(a/@ <(dec a)>)) 'a')
35− "96a"
59+"96a"
36− ~zod:dojo> (;~(cmp trip |=(a=@ ~[a a]) |=(a=@ <(dec a)>)) 'acd')
60+~zod:dojo> (;~(cmp trip |=(a/@ ~[a a]) |=(a/@ <(dec a)>)) 'acd')
37− "96acd"
61+"96acd"
38−
62+```
39−Multiple gates are equivalent to stacked semsigs.
40−
41−------------------------------------------------------------------------
42−
43− [~ 0]
44− ~zod:dojo> ((slat %p) '~nec')
45− [~ 1]
46− ~zod:dojo> ((slat %p) 'nec')
47− ~
48− ~zod:dojo> ;~(biff (slat %p))
49− <1.ags [txt=@ta <1.wqj [mod=@tas <374.hzt 100.kzl 1.ypj %164>]>]>
50− ~zod:dojo> (;~(biff (slat %p)) '~zod')
51− [~ 0]
52− ~zod:dojo> (;~(biff (slat %p)) '~')
53− ~
54− ~zod:dojo> (;~(biff (slat %p)) '~nec')
55− [~ 1]
56−
57−More commonly, this can be used for unit composition. `(slat %p)` parses
58−cords in phonetic base, failure case: invalid text
59−
60− ~zod:dojo> (mo [~nec 12] [~tug 16] ~)
61− {[p=~nec q=12] [p=~tug q=16]}
62− ~zod:dojo> ~(get by (mo [~nec 12] [~tug 16] ~))
63− <1.yvn [* <18.wzi [a=nlr([p=@p q=@ud]) <374.hzt 100.kzl 1.ypj %164>]>]>
64− ~zod:dojo> =yaz ~(get by (mo [~nec 12] [~tug 16] ~))
65− ~zod:dojo> (yaz ~nec)
66− [~ 12]
67− ~zod:dojo> (yaz ~zod)
68− ~
69− ~zod:dojo> (yaz ~tug)
70− [~ 16]
71−
72−`mo` makes a map, and `+-get`:by is used to retrieve values from one,
73−failure case: no such key
74−
75− ~zod:dojo> (;~(biff (slat %p) yaz) '~zod')
76− ~
77− ~zod:dojo> (;~(biff (slat %p) yaz) '~nec')
78− [~ 12]
79− ~zod:dojo> (;~(biff (slat %p) yaz) 'tug')
80− ~
81− ~zod:dojo> (;~(biff (slat %p) yaz) '~tug')
82− [~ 16]
83−
84− ~zod:dojo> (;~(biff (slat %p) yaz |=(a=@ud [~ (add 100 a)])) '~nec')
85− [~ 112]
86− ~zod:dojo> (;~(biff (slat %p) yaz |=(a=@ud [~ (add 100 a)])) '~zod')
87− ~
88− ~zod:dojo> (;~(biff (slat %p) yaz |=(a=@ud [~ (add 100 a)])) 'mal')
89− ~
90−
91−These can be combined with `biff`, which connects a previous succeeded
92−unit result by a gate that itself produces a unit from it.
93−
94−------------------------------------------------------------------------
95−
96− ~zod:dojo> (hep [1 1] "")
97− [p=[p=1 q=1] q=~]
98− ~zod:dojo> (hep [1 1] "-")
99− [p=[p=1 q=2] q=[~ [p=~~- q=[p=[p=1 q=2] q=""]]]]
100− ~zod:dojo> `(like cord)`(hep [1 1] "-")
101− [p=[p=1 q=2] q=[~ [p='-' q=[p=[p=1 q=2] q=""]]]]
102− ~zod:dojo> `(like cord)`(hep [1 1] "?")
103− [p=[p=1 q=1] q=~]
104− ~zod:dojo> (lus [1 1] "+")
105− [p=[p=1 q=2] q=[~ [p=~~~2b. q=[p=[p=1 q=2] q=""]]]]
106− ~zod:dojo> `(like cord)`(lus [1 1] "+")
107− [p=[p=1 q=2] q=[~ [p='+' q=[p=[p=1 q=2] q=""]]]]
108− ~zod:dojo> `(like cord)`(lus [1 1] "++")
109− [p=[p=1 q=2] q=[~ [p='+' q=[p=[p=1 q=2] q="+"]]]]
110− ~zod:dojo> `(like cord)`(lus [1 1] " +")
111− [p=[p=1 q=1] q=~]
112− ~zod:dojo> `(like cord)`(;~(pose hep lus) [1 1] "?")
113− [p=[p=1 q=1] q=~]
114− ~zod:dojo> `(like cord)`(;~(pose hep lus) [1 1] "-")
115− [p=[p=1 q=2] q=[~ [p='-' q=[p=[p=1 q=2] q=""]]]]
116− ~zod:dojo> `(like cord)`(;~(pose hep lus) [1 1] "+")
117− [p=[p=1 q=2] q=[~ [p='+' q=[p=[p=1 q=2] q=""]]]]
118− ~zod:dojo> `(like cord)`(;~(pose hep lus) [1 1] "a")
119− [p=[p=1 q=1] q=~]
120− ~zod:dojo> `(like cord)`(;~(pose hep lus) [1 1] "-+")
121− [p=[p=1 q=2] q=[~ [p='-' q=[p=[p=1 q=2] q="+"]]]]
122− ~zod:dojo> `(like ,[cord cord])`(;~(plug hep lus) [1 1] "+")
123− [p=[p=1 q=1] q=~]
124− ~zod:dojo> `(like ,[cord cord])`(;~(plug hep lus) [1 1] "-+")
125− [p=[p=1 q=3] q=[~ [p=['-' '+'] q=[p=[p=1 q=3] q=""]]]]
126− ~zod:dojo> `(like ,[cord cord])`(;~(plug hep lus) [1 1] "-+ ")
127− [p=[p=1 q=3] q=[~ [p=['-' '+'] q=[p=[p=1 q=3] q=" "]]]]
128−
129−Most prominently, however, `;~` is used for combinator parsers,
130−composing [rule]s in various ways
131−
132−See parsing sections 2eA - 2eH, and specifically section 2eD, for more
133−information.
docs/programming/hoon/catalog/sig-hint/bar-show.md+22−9
@@ -1,14 +1,27 @@
1−# `:show`, `~|` "sigbar", `{$show p/twig q/twig}`
1+---
2+sort: 2
3+---
2
4
3−`p` in stack trace if `q` crashes.
5+# `:show ~| "sigbar" {$show p/seed q/seed}`
4
6
5−Produces: `p` in the stack trace if `q` crashes. `p` is only
7+Tracing printf.
6−evaluated if `q` crashes.
7
8
8−Regular form: *2-fixed*
9+## Expands to
9
10
10−Examples:
11+`q`.
11
12
13+## Convention
14+
15+Prettyprints `p` in stack trace if `q` crashes.
16+
17+## Syntax
18+
19+Regular: *2-fixed*.
20+
21+## Examples
22+
23+```
12− > ~|('sample error message' !!)
24+~zod:dojo> ~|('sample error message' !!)
13− 'sample error message'
25+'sample error message'
14− ford: build failed ~[/g/~sivtyv-barnel/use/dojo/~sivtyv-barnel/inn/hand /g/~sivtyv-barnel/use/hood/~sivtyv-barnel/out/dojo/drum/phat/~sivtyv-barnel/dojo /d //term/1]
26+ford: build failed
27+```
docs/programming/hoon/catalog/sig-hint/buc-poll.md+21−11
@@ -1,16 +1,26 @@
1−# `:poll`, `~$` "sigbuc", `{$poll p/term q/twig}`
1+---
2+sort: 12
3+---
2
4
3−Label for profiling.
5+# `:poll ~$ "sigbuc" {$poll p/term q/seed}`
4
6
5−Labels computation `q` as `p` for profiling.
7+Profiling hit counter.
6
8
7−Irregular form: *2-fixed*
9+## Expands to
8
10
9−Examples:
11+`q`.
10
12
11− ~zod:dojo> (make '~$(foo |-($))')
13+## Convention
12− [%10 p=[p=1.702.259.052 q=[%1 p=7.303.014]] q=[%8 p=[%1 p=[9 2 0 1]] q=[%9 p=2 q=[%0 p=1]]]]
14+
13− ~zod:dojo> `@tas`1.702.259.052
15+If profiling is on, adds 1 to the hit counter for `p`.
14− %live
16+
17+## Syntax
18+
19+Regular: *2-fixed*.
20+
21+## Examples
22+
23+```
15− ~zod:dojo> `@tas`7.303.014
24+~zod:dojo> ~$(%foo 3)
16− %foo
25+3
26+```
docs/programming/hoon/catalog/sig-hint/cab-lurk.md+22−10
@@ -1,15 +1,27 @@
1−# `:lurk`, `~_`, "sigcab", `{$lurk p/twig q/twig}`
1+---
2+sort: 3
3+---
2
4
3−Pre-formatted stackframe into stacktrace.
5+# `:lurk ~_ "sigcab" {$lurk p/seed q/seed}`
4
6
5−Inserts pre-formatted stackframe `p` into the stacktrace of `q`.
7+User-formatted tracing printf.
6−In hoon terminology, inserts `p`, a trap producing a ++`tank` (pretty printed text), in the trace of `q`.
7
8
8−Regular form: *2-fixed*
9+## Expands to
9
10
10−Examples:
11+`q`.
11
12
12− ~zod:dojo> (make '~_(+216 ~)')
13+## Convention
13− [%10 p=[p=1.851.876.717 q=[p=[%1 p=[0 216]] q=[%0 p=1]]] q=[%1 p=0]]
14+
14− ~zod:dojo> `@tas`1.851.876.717
15+Shows `p` in stacktrace if `q` crashes.
15− %mean
16+
17+## Discussion
18+
19+`p` must produce a `tank` (prettyprint source).
20+
21+## Examples
22+
23+```
24+~zod:dojo> ~_([%leaf "sample error message"] !!)
25+"sample error message"
26+ford: build failed
27+```
docs/programming/hoon/catalog/sig-hint/cen-fast.md+69−3
@@ -1,12 +1,78 @@
1−# `:fast`, `~%` "sigcen", `{$fast p/chum q/twig r/tyre s/twig}`
1+---
2+sort: 10
3+---
2
4
5+# `:fast ~% "sigcen" {$fast p/term q/wing r/(list {term seed}) s/seed}`
6+
3−General jet hint.
7+General jet hint.
8+
9+## Expands to
10+
11+`s`.
12+
13+## Convention
14+
15+Register a core with name `p`, with parent at leg `q`, exporting
16+the named formulas `r`, constructed by `s`.
17+
18+## Syntax
19+
20+Regular: *4-fixed*. For `r`, use `~` if empty. Otherwise, *jogging*
21+between opening and closing `==`.
22+
23+## Discussion
24+
25+`:fast` is for registering cores. A registered core declares its
26+formal identity to the interpreter, which may or may not be able
27+to recognize and/or accelerate it.
28+
29+Registered cores are are organized in a containment hierarchy.
30+The parent core is at any leg within the child core. When we
31+register a core, we state the leg to its parent, in the form of
32+wing `q`. We assume the parent is already registered -- as it
33+must be, if (a) we registered it on creation, (b) the child was
34+created by an arm defined on the parent.
35+
36+(Cores are actually managed by their formula/battery. Any
37+function call will create a new core with a new sample, but
38+batteries are constant. But it is not sufficient to match the
39+battery -- matching the semantics constrains the payload as well,
40+since the semantics of a battery may depend on any parent core
41+and/or payload constant.)
42+
43+The purpose of registration is always performance-related. It
44+may involve (a) a special-purpose optimizer or "jet", written
45+for a specific core and checked with a Merkle hash; (b) a
46+general-purpose hotspot optimizer or "JIT"; or (c) merely a
47+hotspot declaration for profiling.
48+
49+As always with hints, the programmer has no idea which of (a),
50+(b), and (c) will be applied. She should use `:fast`
51+indiscriminately on all hotspots, bottlenecks, etc, real or
52+suspected.
53+
54+The list `r` is a way for the Hoon programmer to help jet
55+implementors with named Nock formulas that act on the core.
56+In complex systems, jet implementations are often partial and
57+want to call back into userspace.
58+
59+The child core contains the parent, of course. When we register
60+a core, we state the leg to its parent, in the form of wing `q`.
61+We assume that the parent -- any core within the payload -- is
62+already registered.
63+
64+must already be registered.
65+The interpreter can thus
66+
67+`p` is the name of this core within its parent; `q` is a the leg
4
68
5Registers a jet in core `s` so that it can be called when that code is run.
69Registers a jet in core `s` so that it can be called when that code is run.
6
70
7Regularm form: *4-fixed*
71Regularm form: *4-fixed*
8
72
9−Examples:
73+## Examples
74+
75+Here's the AES
10
76
11 ++ aesc :: AES-256
77 ++ aesc :: AES-256
12 ~% %aesc + ~
78 ~% %aesc + ~
docs/programming/hoon/catalog/sig-hint/fas-funk.md+23−12
@@ -1,17 +1,28 @@
1−# `:funk`, `~/`, "sigfas", `{$funk p/chum q/twig}`
1+---
2+sort: 1
2
3
3−XX HELP
4+# `:funk ~/ "sigfas" {$funk p/term q/twig}`
4
5
5−`~/` is a synthetic rune that implements one common case - a function arm in
6+Jet hint for a gate whose context is a registered core.
6−a book, i.e. a library function - of the `~%` jet hint. Assumes the parent axis is `7` and that there are no children.
7
7
8−Regular form: *2fixed*
8+## Expands to
9
9
10−Examples:
10+```
11+:fast(p +7 ~ q)
12+```
11
13
12− ~zod:dojo> (make '~/ %bam |.(40)')
14+## Syntax
13− [%8 p=[%1 p=[1 40]] q=[%10 p=[p=1.953.718.630 q=[%1 p=[7.168.354 [0 7] 0]]] q=[%0 p=1]]]
15+
14− ~zod:dojo> `@`%bam
16+Regular: *2-fixed*.
15− 7.168.354
17+
16− ~zod:dojo> `@tas`1.953.718.630
18+## Examples
17− %fast
19+
20+From the kernel:
21+```
22+++ add
23+ ~/ %add
24+ |= {a/@ b/@}
25+ ^- @
26+ ?: =(0 a) b
27+ $(a (dec a), b +(b))
28+```
docs/programming/hoon/catalog/sig-hint/gal-thin.md+25−11
@@ -1,16 +1,30 @@
1−# `~<`, "siggal", `{$thin p/$@(term {p/term q/twig}) q/twig}`
1+---
2+sort: 6
3+---
2
4
3−Hint to product.
5+# :thin ~< "siggal" {$thin p/$@(term {p/term q/twig}) q/twig}
4
6
5−`~<` is a synthetic rune that applies arbitrary hint `p` to the
7+Raw hint, applied to the result of computation.
6−product of `q`. `~<` is similar to `~>`, but computes `q` before
7−applying the hint `p`.
8
8
9−Irregular form: *2-fixed*
9+## Expands to
10
10
11−Examples:
11+`q`.
12
12
13+## Syntax
14+
15+Regular: *2-fixed*. For the dynamic form, write `%term.twig`.
16+
17+## Discussion
18+
19+`:thin` is only used for jet hints (`:funk` and `:fast`) at the
20+moment; we are not telling the interpreter something about the
21+computation we're about to perform, but rather about the result.
22+
23+## Examples
24+
25+```
13− ~zod:dojo> (make '~<(%a 42)')
26+~zod:dojo> (make '~<(%a 42)')
14− [%7 p=[%1 p=42] q=[%10 p=97 q=[%0 p=1]]]
27+[%7 p=[%1 p=42] q=[%10 p=97 q=[%0 p=1]]]
15− ~zod:dojo> (make '~<(%a.+(.) 42)')
28+~zod:dojo> (make '~<(%a.+(.) 42)')
16− [%7 p=[%1 p=42] q=[%10 p=[p=97 q=[%4 p=[%0 p=1]]] q=[%0 p=1]]]
29+[%7 p=[%1 p=42] q=[%10 p=[p=97 q=[%4 p=[%0 p=1]]] q=[%0 p=1]]]
30+```
docs/programming/hoon/catalog/sig-hint/gar-hint.md+31−9
@@ -1,14 +1,36 @@
1−# `:hint`, `~>` "siggar", {$hint p/$@(term {p/term q/twig}) q/twig}
1+---
2+sort: 5
3+---
2
4
3−Arbitrary hint
5+# `:hint ~> "siggar", {$hint p/$@(term {p/term q/twig}) q/twig}`
4
6
5−Applies arbitrary hint `p` to `q`.
7+Raw hint, applied before computation.
6
8
7−Regular form: *2-fixed*
9+## Expands to
8
10
9−Examples:
11+`q`.
10
12
13+## Syntax
14+
15+Regular: *2-fixed*. For the dynamic form, write `%term.twig`.
16+
17+## Discussion
18+
19+Hoon has no way of telling what hints are used and what aren't.
20+Hints are all conventions at the interpreter level.
21+
22+## Examples
23+
24+```
11− ~zod:dojo> (make '~>(%a 42)')
25+~zod:dojo> ~>(%a 42)
26+42
27+```
28+
29+Running the compiler:
30+
31+```
32+~zod:dojo> (make '~>(%a 42)')
12− [%10 p=97 q=[%1 p=42]]
33+[%10 p=97 q=[%1 p=42]]
13− ~zod:dojo> (make '~>(%a.+(2) 42)')
34+~zod:dojo> (make '~>(%a.+(2) 42)')
14− [%10 p=[p=97 q=[%4 p=[%1 p=2]]] q=[%1 p=42]]
35+[%10 p=[p=97 q=[%4 p=[%1 p=2]]] q=[%1 p=42]]
36+```
docs/programming/hoon/catalog/sig-hint/lus-memo.md+37−18
@@ -1,24 +1,43 @@
1−# `:memo`, `~+`, "siglus", `{$memo p/@ q/twig}`
1+---
2+sort: 7
3+---
2
4
3−Memoize computation.
5+# :memo ~+ "siglus" {$memo p/seed}`
4
6
5−Hints to the interpreter to memoize (cache) the computation of `p`.
7+Cache a computation.
6
8
7−Regular form: *1-fixed*
9+## Expands to
8
10
9−Examples:
11+`p`.
10
12
11− ~zod:dojo> 20
13+## Convention
12− 20
13− ~zod:dojo> ~+(20)
14− 20
15− ~zod:dojo> 20
16− ~zod:dojo> (make '20')
17− [%1 p=20]
18− ~zod:dojo> (make '~+(20)')
19− [%10 p=[p=1.869.440.365 q=[%1 p=0]] q=[%1 p=20]]
20− ~zod:dojo> `@tas`1.869.440.365
21− %memo
22
14
23−By using `++make` to display the compiled nock, we can see that `~+`
15+Caches the formula and subject of `p` in a local cache (generally
24−inserts a `%memo` hint.
16+transient in the current event).
17+
18+## Syntax
19+
20+Regular: *1-fixed*.
21+
22+## Examples
23+
24+This may pause for a second:
25+
26+```
27+~zod:dojo> %.(25 |=(a/@ ?:((lth a 2) 1 (add $(a (sub a 2)) $(a (dec a))))))
28+121.393
29+```
30+
31+This may make you want to press ^C:
32+
33+```
34+~zod:dojo> %.(30 |=(a/@ ?:((lth a 2) 1 (add $(a (sub a 2)) $(a (dec a))))))
35+1.346.269
36+```
37+
38+This should work fine:
39+
40+```
41+~zod:dojo> %.(100 |=(a/@ ~+(?:((lth a 2) 1 (add $(a (sub a 2)) $(a (dec a)))))))
42+573.147.844.013.817.084.101
43+```
docs/programming/hoon/catalog/sig-hint/pam-dump.md+20−11
@@ -1,18 +1,27 @@
1−# `:dump`, `~&`, "sigpam", `{$dump p/@ud q/twig r/twig}`
1+---
2+sort: 1
3+---
2
4
3−Printf.
5+# `:dump ~& "sigpam" {$dump p/seed q/seed}`
4
6
5−Prints `q` on the console before computing `r`. `p` is the log priority, 0-3
7+Debugging printf.
6−defaulting to 0. `p` is optional and is rarely used.
7
8
8−Regular form: *fixed 2 or 3*
9+## Expands to
9
10
11+`q`.
10
12
11−Examples:
13+## Convention
12
14
13− ~zod:dojo> ~&('oops' ~)
15+Prettyprints `p` on the console before computing `q`.
14− 'oops'
15− ~
16
16
17−The most common use of `~&`: print something to the console before
17+## Syntax
18−proceeding.
18+
19+Regular: *2-fixed*.
20+
21+## Examples
22+
23+```
24+~zod:dojo> ~&('halp' ~)
25+'halp'
26+~
27+```
docs/programming/hoon/catalog/sig-hint/tis-ddup.md+29−18
@@ -1,23 +1,34 @@
1−# `:ddup`, `~=` "sigtis", `{$ddup p/twig q/twig}`
1+---
2+sort: 8
3+---
2
4
3−Hint to avoid duplication.
5+# `:ddup ~= "sigtis" {$ddup p/seed q/seed}`
4
6
5−Hints to the interpreter that `q` may produce a noun equal to the
7+Detect a duplicate.
6−already existing `p` in order to avoid storing the same noun twice.
7
8
8−Regular form: *2-fixed*
9+## Expands to
9
10
10−Examples:
11+`q`.
11
12
12− ~zod:dojo> 20
13+## Convention
13− 20
14+
14− ~zod:dojo> =+(a=20 20)
15+If `p` equals `q`, produce `p` instead of `q`.
15− 20
16+
17+## Discussion
18+
19+Duplicates are especially bad news in Hoon, because comparing them
20+takes O(n) time. Use `~=` to kill them as they breed.
21+
22+## Examples
23+
24+This code traverses a tree and replaces all instances of `42` with
25+`420`:
26+
27+```
16− ~zod:dojo> =+(a=20 ~=(a 20))
28+~zod:dojo> =foo |= a/(tree)
17− 20
29+ ?~(a ~ ~=(a [?:(=(n.a 42) 420 n.a) $(a l.a) $(a r.a)]))
18− ~zod:dojo> (make '=+(a=20 20)')
19− [%8 p=[%1 p=20] q=[%1 p=20]]
20− ~zod:dojo> (make '=+(a=20 ~=(a 20))')
30+~zod:dojo> (foo 42 ~ ~)
21− [%8 p=[%1 p=20] q=[%10 p=[p=1.836.213.607 q=[%0 p=2]] q=[%1 p=20]]]
31+[420 ~ ~]
22− ~zod:dojo> `@tas`1.836.213.607
32+```
23− %germ
33+
34+Without `~=`, it would build a copy of a completely unchanged tree. Sad!
docs/programming/hoon/catalog/sig-hint/wut-warn.md+23−14
@@ -1,20 +1,29 @@
1−# `:warn`, `~?`, "sigwut", `{$warn p/@ud q/twig r/twig s/twig}`
1+---
2+sort: 4
3+---
2
4
3−PrintF if `q` true.
5+# `:warn ~? "sigwut" `{$warn p/twig q/twig r/twig}`
4
6
5−Same as `~&` except for that `r` is printed to the console if and only
7+Conditional debugging printf.
6−if `q` evaluates to true. `p` is the priority level between 1-3 (defaults to 0) and is both optional and rarely used.
7
8
8−Regularm form *4-fixed*
9+## Expands to
9
10
10−Examples:
11+`r`.
11
12
12− ~zod:dojo> ~?((gth 1 2) 'oops' ~)
13+## Convention
13− ~
14− ~zod:dojo> ~?((gth 1 0) 'oops' ~)
15− 'oops'
16− ~
17
14
18−A simple case of the conditional printf. When our condition evaluates to
15+If `p` is true, prettyprints `q` on the console before computing `r`.
19−true we print our `r`. Most useful in computation dealing with dynamic
16+
20−data.
17+## Syntax
18+
19+Regular: *4-fixed*.
20+
21+## Examples
22+
23+```
24+~zod:dojo> ~?((gth 1 2) 'oops' ~)
25+~
26+~zod:dojo> ~?((gth 1 0) 'oops' ~)
27+'oops'
28+~
29+```
docs/programming/hoon/catalog/sig-hint/zap-peep.md+21−21
@@ -1,29 +1,29 @@
1+---
2+sort: 9
3+---
4+
1−# `:peep`, `~!`, "sigzap", `{$peep p/twig q/twig}`
5+# `:peep ~! "sigzap" {$peep p/seed q/seed}`
2
6
3Print type on compilation fail.
7Print type on compilation fail.
4
8
5−Produces the type of `p` on the stacktrace if `q` fails. Used only for debugging purposes.
9+## Expands to
10+
11+`q`.
12+
13+## Convention
6
14
7−Examples:
15+If compilation of `q` fails, prints the span of `p` in the trace.
8
16
9− ~zod:dojo> a
17+## Syntax
10− ! -find-limb.a
11− ! find-none
12− ! exit
13− ~zod:dojo> ~!('foo' a)
14− ! @t
15− ! -find-limb.a
16− ! find-none
17− ! exit
18
18
19−When trying to compute an unassigned variable, `a` we produce the type
19+Regular: *2-fixed*.
20−of `'foo'`, `@t`.
21
20
22− ~zod:dojo> ~!(%foo a)
21+## Examples
23− ! %foo
24− ! -find-limb.a
25− ! find-none
26− ! exit
27
22
28−Again, we use our unassigned variable `a` and the cube `%foo`, whose
23+```
29−type is in fact `%foo`.
24+~zod:dojo> a
25+! -find.a
26+~zod:dojo> ~!('foo' a)
27+! @t
28+! find.a
29+```
docs/programming/hoon/catalog/tis-flow/bar-new.md+38
@@ -0,0 +1,38 @@
1+---
2+sort: 5
3+---
4+
5+# `:new, =|, "tisbar", {$new p/moss q/seed}`
6+
7+Combine a defaulted mold with the subject.
8+
9+## Expands to
10+
11+```
12+:pin(:bunt(p) q)
13+```
14+
15+## Syntax
16+
17+Regular: *2-fixed*.
18+
19+## Discussion
20+
21+`:new` "declares a variable" which is "uninitialized," presumably
22+because you'll set it in a loop or similar.
23+
24+A common mistake is to forget that since `p` is moldy,
25+`:new(foo=@ bar)` is wrong; you mean `:new(foo/@ bar)`, since
26+`foo=@` is `:name(foo @)` (putting a face on a seed) and `foo/@`
27+is `:coat(foo @)` (wrapping a face around a mold).
28+
29+## Examples
30+
31+```
32+~zod:dojo> =foo |= a/@
33+ =| b/@
34+ =- :(add a b c)
35+ c=2
36+~zod:dojo> (foo 5)
37+7
38+```
docs/programming/hoon/catalog/tis-flow/col-fix.md+28
@@ -0,0 +1,28 @@
1+---
2+sort: 9
3+---
4+
5+# `:fix, =:, "tiscol", {$fix p/(list (pair wing twig)) q/twig}`
6+
7+Mutate multiple legs in the subject.
8+
9+## Expands to
10+
11+```
12+:per(:keep(. p q) r)
13+```
14+
15+## Syntax
16+
17+Regular: *jogging*, then *1-fixed*.
18+
19+## Examples
20+
21+```
22+~zod:dojo> =+ a=[b=1 c=2]
23+ =: c.a 4
24+ b.a 3
25+ ==
26+ a
27+[b=3 c=4]
28+```
docs/programming/hoon/catalog/tis-flow/dot-set.md+35
@@ -0,0 +1,35 @@
1+---
2+sort: 8
3+---
4+
5+# `:set, =., "tisdot", {$set p/wing q/seed r/seed}`
6+
7+Mutate a leg in the subject.
8+
9+## Expands to
10+
11+```
12+:per(:keep(. p q) r)
13+```
14+
15+## Syntax
16+
17+Regular: *3-fixed*.
18+
19+## Discussion
20+
21+As usual, we are not actually mutating the subject, just creating
22+a new subject with a changed value. Note that the mutation uses
23+`:keep` (`%_`), so the type doesn't change.
24+
25+## Examples
26+
27+```
28+~zod:dojo> =+ a=[b=1 c=2]
29+ =. b.a 3
30+ a
31+[b=3 c=2]
32+~zod:dojo> =+ a=[b=1 c=2]
33+ =.(b.a 3 a)
34+[b=3 c=2]
35+```
docs/programming/hoon/catalog/tis-flow/fas-var.md+35
@@ -0,0 +1,35 @@
1+---
2+sort: 6
3+---
4+
5+# `:var, =/, "tisfas", {$var p/taco q/twig r/twig}`
6+
7+Combine a named and/or typed noun with the subject.
8+
9+## Expands to
10+
11+```
12+?@(p :pin(:name(p q) r) :pin(:cast(:(coat p) q) r)
13+```
14+
15+## Syntax
16+
17+Regular: *3-fixed*.
18+
19+## Discussion
20+
21+`p` can be either a symbol or a symbol/mold. If it's just a
22+symbol, `:var` "declares a type-inferred variable." It has a
23+mold, `:var` "declares a type-checked variable."
24+
25+## Examples
26+
27+```
28+~zod:dojo> =foo |= a/@
29+ =/ b 1
30+ =/ c/@ 2
31+ :(add a b c)
32+~zod:dojo> (foo 5)
33+8
34+```
35+
docs/programming/hoon/catalog/tis-flow/gal-rap.md+28
@@ -0,0 +1,28 @@
1+---
2+sort: 2
3+---
4+
5+# `:rap, =<, "tisgal", {$rap p/twig q/twig}`
6+
7+Compose two twigs, inverted.
8+
9+## Expands to
10+
11+```
12+:per(q p)
13+```
14+
15+## Syntax
16+
17+Regular: *2-fixed*.
18+
19+Irregular: `foo:bar` is `:rap(foo bar)`.
20+
21+## Examples
22+
23+```
24+~zod:dojo> b:[a=1 b=2 c=3]
25+2
26+~zod:dojo> [. .]:(add 2 4)
27+[6 6]
28+```
docs/programming/hoon/catalog/tis-flow/gar-per.md+24
@@ -0,0 +1,24 @@
1+---
2+sort: 1
3+---
4+
5+# `:per, =>, "tisgar", {$per p/twig q/twig}`
6+
7+Compose two twigs.
8+
9+## Produces
10+
11+`q`, compiled against the product of `p`.
12+
13+## Syntax
14+
15+Regular: *2-fixed*.
16+
17+## Examples
18+
19+```
20+~zod:dojo> =>([a=1 b=2 c=3] b)
21+2
22+~zod:dojo> =>((add 2 4) [. .])
23+[6 6]
24+```
docs/programming/hoon/catalog/tis-flow/hep-nip.md+33
@@ -0,0 +1,33 @@
1+---
2+sort: 4
3+---
4+
5+# `:nip, =-, "tishep", {$pin p/seed q/seed}`
6+
7+Combine a new noun with the subject, inverted.
8+
9+## Expands to
10+
11+```
12+:per(:cons(q .) p)
13+```
14+
15+## Syntax
16+
17+Regular: *2-fixed*.
18+
19+## Discussion
20+
21+`:nip` looks better than `:pin` when the twig you're pinning
22+is much smaller than the twig that uses it.
23+
24+## Examples
25+
26+```
27+~zod:dojo> =foo |= a/@
28+ =+ :name(b 1)
29+ =- :(add a b c)
30+ c=2
31+~zod:dojo> (foo 5)
32+8
33+```
docs/programming/hoon/catalog/tis-flow/ket-sip.md+40
@@ -0,0 +1,40 @@
1+---
2+sort: 10
3+---
4+
5+# `:sip, =^, "tisket", {$sip p/taco q/wing r/twig s/twig}`
6+
7+Pin the head of a pair; mutate a leg with the tail.
8+
9+## Expands to
10+
11+```
12+:var(p -.r :set(q +.r s))
13+```
14+
15+## Syntax
16+
17+Regular: *4-fixed*.
18+
19+## Discussion
20+
21+We use `:sip` when we have a state machine with a function that
22+produces a cell, whose head is a result and whose tail is a new
23+state. We want to use the head as a new variable, and stuff the
24+tail back into wherever we stored the old state.
25+
26+This may also remind you of Haskell's State monad.
27+
28+## Examples
29+
30+The `og` core is a stateful pseudo-random number generator.
31+We have to change the core state every time we generate a
32+random number, so we need to `:sip`:
33+
34+```
35+~zod:dojo> =+ rng=~(. og 420)
36+ =^ r1 rng (rads:rng 100)
37+ =^ r2 rng (rads:rng 100)
38+ [r1 r2]
39+[99 46]
40+```
docs/programming/hoon/catalog/tis-flow/lus-pin.md+32
@@ -0,0 +1,32 @@
1+---
2+sort: 3
3+---
4+
5+# `:pin, =+, "tislus", {$pin p/seed q/seed}`
6+
7+Combine a new noun with the subject.
8+
9+## Expands to
10+
11+```
12+:per(:cons(p .) q)
13+```
14+
15+## Syntax
16+
17+Regular: *2-fixed*.
18+
19+## Discussion
20+
21+`:pin` is the simplest way of "declaring a variable."
22+
23+## Examples
24+
25+```
26+~zod:dojo> =foo |= a/@
27+ =+ :name(b 1)
28+ =+ c=2
29+ :(add a b c)
30+~zod:dojo> (foo 5)
31+8
32+```
docs/programming/hoon/catalog/tis-flow/sem-rev.md+28
@@ -0,0 +1,28 @@
1+---
2+sort: 7
3+---
4+
5+# `:rev, =;, "tissem", {$rev p/taco q/twig r/twig}`
6+
7+Combine a named and/or typed noun with the subject, inverted.
8+
9+## Expands to
10+
11+```
12+?@(p :pin(:name(p r) q) :pin(:cast(:(coat p) r) q)
13+```
14+
15+## Syntax
16+
17+Regular: *3-fixed*.
18+
19+## Examples
20+
21+```
22+~zod:dojo> =foo :gate a/@
23+ :var b 1
24+ :rev c/@ :(add a b c)
25+ 2
26+~zod:dojo> (foo 5)
27+8
28+```
docs/programming/hoon/catalog/tis-flow/sig-tow.mddeleted

No changes to the content.

docs/programming/hoon/catalog/tis-flow/tar-aka.md+37
@@ -0,0 +1,37 @@
1+---
2+sort: 11
3+---
4+
5+# `:aka, =*, "tistar", {$aka p/term q/seed r/seed}`
6+
7+Define an alias.
8+
9+## Produces
10+
11+`r`, compiled with a subject in which `p` is aliased to `q`.
12+
13+## Syntax
14+
15+Regular: *3-fixed*.
16+
17+## Discussion
18+
19+The difference between aliasing and pinning is that the subject
20+noun stays the same; the alias is just recorded in its span.
21+`q` is calculated every time you use the `p` alias, of course.
22+
23+## Examples
24+
25+```
26+~zod:dojo>
27+ =+ a=1
28+ =* b a
29+ [a b]
30+[1 1]
31+~zod:dojo>
32+ =+ a=1
33+ =* b a
34+ =. a 2
35+ [a b]
36+[2 2]
37+```
docs/programming/hoon/catalog/tis-flow/ts/tsbr.mddeleted−48
@@ -1,48 +0,0 @@
1−# `:new`, `=|`, "tisbar", `{$new p/twig q/twig}`
2−
3−Default value.
4−
5−Produces the default value of input type (aka mold) `p` and makes it
6−available/pushes it onto `q`.
7−
8−
9−`=|` is a synthetic rune that pushes the bunt, or default value, of
10−`p` on the subject and sends it to `q`.
11−
12−Produces
13−--------
14−
15−Twig: `[%tsbr p=mold q=twig]`
16−
17−Accepts
18−-------
19−
20−`p` is a mold. `q` is a twig.
21−
22−Tall form
23−---------
24−
25− =| p
26− q
27−
28−Wide form
29−---------
30−
31− =|(p q)
32−
33−Examples
34−--------
35−
36− ~zod:dojo> =|(a/@p a)
37− ~zod
38−
39−Here we use `=|` to generate the default value of a `@p`, which is
40−`~zod`.
41−
42− /~zod:dojo>
43− =| a=[b/@ c/@]
44− [+(b.a) +(+(c.a))]
45− [1 2]
46−
47−Here we add the bunt of `a/[b/@ c/@]` and perform a very basic operation
48−on it.
docs/programming/hoon/catalog/tis-flow/ts/tscl.mddeleted−20
@@ -1,20 +0,0 @@
1−# `:fix`, `=:`, "tiscol", `{$fix p/(list (pair wing twig)) q/twig}`
2−
3−List of changes.
4−
5−Makes a list of changes `p` to the subject and then evaluates `q`.
6−Useful when you need to make a batch of changes to your subject.
7−
8−Regular form: *jogging*
9−
10−Examples:
11−
12− ~zod:dojo> =+ a=[b=1 c=2]
13− =: c.a 4
14− b.a 3
15− ==
16− a
17− [b=3 c=4]
18−
19−Here we add a simple cell with faces to our subject, `a=[b=1 c=2]` and
20−make a set of changes to it using `=:`.
docs/programming/hoon/catalog/tis-flow/ts/tsdt.mddeleted−21
@@ -1,21 +0,0 @@
1−`=. tisdot`
2−
3−Change value.
4−
5−Produces `r` with `p` in the subject set to `q`. Allows you to change
6−a value in your subject before executing more code against it.
7−
8−Regular form: *3-fixed*
9−
10−Examples:
11−
12− ~zod:dojo> =+ a=[b=1 c=2]
13− =. b.a 3
14− a
15− [b=3 c=2]
16− ~zod:dojo> =+ a=[b=1 c=2]
17− =.(b.a 3 a)
18− [b=3 c=2]
19−
20−Here we see the tall and wide forms of `=.` used to manipulate our
21−simple subject `a=[b=1 c=2]`.
docs/programming/hoon/catalog/tis-flow/ts/tsgl.mddeleted−32
@@ -1,32 +0,0 @@
1−# `:rap`, `=<`, "tisgal" `{$rap p/twig q/twig}`
2−
3−Inverted `=>`: `q` as subject of `p`.
4−
5−Uses the product of `q` as the subject of formula
6−`p`. Allows us to keep the heavier of `p` `q` as the bottom expression, which
7−makes for more readable code. Please see the syntax section for more detail.
8−
9−Regular form: *2-fixed*
10−
11−Examples:
12−
13−
14− ~zod:dojo> b:[a=1 b=2 c=3]
15− 2
16− ~zod:dojo> [. .]:(add 2 4)
17− [6 6]
18−
19−In this simple example we first produce `b` from the tuple
20−`[a=1 b=2 c=3]` using the irregular form of `=<`. Then we use `.` to
21−produce our context from the computation `(add 2 4)` as a cell, `[6 6]`.
22−
23− ~zod:dojo> =< lom
24− |%
25− ++ lom (add 2 tak)
26− ++ tak 4
27− --
28− 6
29−
30−This example is a more common case, where we want to pull some specific
31−value out of a longer computation. Here we use the tall form of `=<` to
32−pull the arm `lom` from the core created with `|%`.
docs/programming/hoon/catalog/tis-flow/ts/tsgr.mddeleted−36
@@ -1,36 +0,0 @@
1−# `:per`, `=>`, "tisgar" `{$per p/twig q/twig}`
2−
3−`p` as subject of `q`.
4−
5−Uses the product of `p` as the subject of formula `q`. For code readability,
6−use `=>` when your `p` isn't as long as `q`, and `=<` when `q` is longer than
7−`p`.
8−
9−Regular form: *2-fixed*
10−
11−Examples:
12−
13− ~zod:dojo> =>([a=1 b=2 c=3] b)
14− 2
15− ~zod:dojo> =>((add 2 4) [. .])
16− [6 6]
17−
18−In this simple example we first produce `b` from the tuple
19−`[a=1 b=2 c=3]` using the wide form of `=>`. Then we use `.` to produce
20−our context from the computation `(add 2 4)` as a cell, `[6 6]`.
21−
22− ~zod:dojo>
23− =cor |= a=@
24− =+ b=0
25− => .(b (add 2 b))
26− => .(a (add a b))
27− [a b]
28− new var %cor
29− /~zod:dojo>
30− (cor 4)
31− [6 2]
32−
33−Here we see a common pattern for using `=>` to conduct procedural
34−changes to values in our subject. First we replace `b` with `b+2` using
35−the irregular form of `%-`, then we replace `a` with the sum of `a` and
36−`b` the same way.
docs/programming/hoon/catalog/tis-flow/ts/tshp.mddeleted−31
@@ -1,31 +0,0 @@
1−# `:nip`, `=-`, "tishep" `{$nip p/twig q/twig}`
2−
3−Inverted `=+`.
4−
5−Pushes variable `q` onto the subject and then
6−executes `p` against the new subject. Allows us to place the larger of `p` and
7−`q` as the bottom expression, making for for more readable code (see the
8−section on backstep in the syntax section).
9−
10−Regular form: *2-fixed*
11−
12−Examples:
13−
14− ~zod:dojo> =- [%a a]
15− [a=1]
16− [%a 1]
17−
18−In this simple example we push `[a=1]` on to our subject, and produce
19−`[%a a]` which pulls the value of `a` from the subject producing
20−`[%a 1]`.
21−
22− ~zod:dojo>
23− =cor |= [a/@ b/@]
24− =- [[%a a] [%b b]]
25− [a b]=[(add a 2) (add a b)]
26− new var %cor
27− ~zod:dojo> (cor 2 4)
28− [[%a 4] %b 6]
29−
30−Here we create a gate `cor` that takes two atoms `a` and `b`. We use
31−`=-` to put the product of our computation first.
docs/programming/hoon/catalog/tis-flow/ts/tskt.mddeleted−32
@@ -1,32 +0,0 @@
1−# `:sip`, `=^`, "tisket" `{$sip p/taco q/wing r/twig s/twig}`
2−====
3−
4−State monad: push a new variable on the subject, change value of another.
5−
6−Similar to `=+` in that it pushes a value `q` on the stack with
7−face (variable name) `p`. It then modifies the new value of `q` within the subject.
8−`r` is the cell of [new-product-p updated-value-1].
9−
10−Regular form: *2-fixed*
11−
12−Examples:
13−
14− > =+ rng=~(. og 0wrando.mseed.12345)
15− =^ r1 rng (rads:rng 100)
16− =^ r2 rng (rads:rng 100)
17− [r1 r2 rng]
18− [99 46 <4.tty [@uw <399.uhj 106.umz 1.lgo %163>]>]
19− ~fodrem-michex:dojo/try>
20−
21−This is an example of using the `++og` pseudorandom number generator
22−with the `=^` rune. `++og` is evaluated with the initial random seed and
23−stored in `rng`. `=^` takes a face (to put on the result), a wing of the
24−subject (to modify), and a twig that must evaluate to a cell. The head
25−of the cell is the result, which is pushed on the subject with the
26−specified face. The tail of the cell is the updated state, which
27−replaces the specified wing of the subject. The final child twig is then
28−evaluated with the new subject.
29−
30−In the case above, `++rads` in `++og` returns a cell of the result and a
31−new `++og` core with the next state of the PRNG. `=^` is useful for any
32−computation that also updates some kind of state.
docs/programming/hoon/catalog/tis-flow/ts/tsls.mddeleted−30
@@ -1,30 +0,0 @@
1−# `:pin`, `=+`, "tislus" `{$pin p/twig q/twig}`
2−
3−Push variable onto the subject.
4−
5−Pushes a new variable `p` onto the subject and then executes `q` against it.
6−Can use `$=` to put an optional face (variable name) on the value.
7−
8−Examples:
9−
10− ~zod:dojo>
11− =+ a=1
12− a
13− 1
14−
15−The simplest case of a `=+`, we push `a=1` on to our subject, and
16−produce `a`.
17−
18− ~zod:dojo>
19− =cor |= a=@
20− =+ b=1
21− =+ c=2
22− :(add a b c)
23− new var %cor
24− ~zod:dojo>
25− (cor 0)
26− 3
27−
28−This is a common case of `=+`, when we need to add intermediate values
29−to our subject to divide up our computation. `=+` makes for procedural,
30−top to bottom code organization.
docs/programming/hoon/catalog/tis-flow/ts/tssg.mddeleted−16
@@ -1,16 +0,0 @@
1−# `:tow`, `=~`, "tissig" `{$tow p/(list twig)}`
2−====
3−
4−List of twigs.
5−
6−Composes a list of twigs. Applies `=>` to a list of expressions, using each result as the
7−subject to the following expression.
8−
9−Regularm form: *running*
10−
11−Examples:
12−
13− ~zod:dojo> =~(1 +(.) +(.))
14− 3
15− ~zod:dojo> =~([1 2] [. [3 4]] [. [5 6]] [. ~])
16− [[[[1 2] 3 4] 5 6] ~]
docs/programming/hoon/catalog/tis-flow/ts/tstr.mddeleted−24
@@ -1,24 +0,0 @@
1−# `:aka`, `=*`, "tistar" `{$aka p/term q/twig r/twig}`
2−
3−Alias.
4−
5−Makes `p` an alias of value `q`, producing a `%bull`, the alias type. Useful when you don't want to write
6−out a long address multiple times, for example `p.s.+.variable`, which translates to `p` within `s` within the tail of `variable`.
7−
8−Examples:
9−
10− ~zod:dojo>
11− =+ a=1
12− =* b a
13− [a b]
14− [1 1]
15− ~zod:dojo>
16− =+ a=1
17− =* b a
18− =. a 2
19− [a b]
20− [2 2]
21−
22−Here we see two simple examples of `=*`, both aliasing `b` to the value
23−of `a`. In our second case you can see that even when we change the
24−value of `a`, `b` continues to point to that value.
docs/programming/hoon/catalog/zap-wild/com-twig.mddeleted−11
@@ -1,11 +0,0 @@
1−# `:twig`, `!,`, "zapcol" `{$twig p/twig q/twig}`
2−
3−XX.
4−
5−Inserts twig `q` as a constant, typed with the type of twig `p`. XX??
6−
7−
8−`!,` is a natural rune that inserts twig `q` as a constant, typed with
9−the type of twig `p`.
10−
11−XX
docs/programming/hoon/catalog/zap-wild/gar-wrap.md+19−27
@@ -1,35 +1,27 @@
1−# `:wrap`, `!>`, "zapgar" `{$wrap p/twig}`
1+---
2+sort: 2
3+---
2
4
3−Produce `[type value]`.
5+# `:wrap !> "zapgar" {$wrap p/twig}`
4
6
5−Produces a cell (known as a `++vase` here) of both the type and value of `p`. Useful for debugging purposes.
7+Wrap a noun in its span.
6
8
7−Regular form: *1-fixed*
9+## Produces
8
10
9−Examples:
11+A cell whose tail is `p`, and whose head is the static span of p.
10
12
11− ~zod:dojo> !>(1)
13+## Syntax
12− [p=[%atom p=%ud] q=1]
13− ~zod:dojo> !>(~zod)
14− [p=[%atom p=%p] q=0]
15
14
16−In these simple examples we see constant type information printed. `1`
15+Regular: *1-fixed*.
17−and `~zod` are shown to be odored atoms of `%ud` and `%p` respectively.
18
16
19− ~zod:dojo> !>([1 2])
17+## Discussion
20− [p=[%cell p=[%atom p=%ud] q=[%atom p=%ud]] q=[1 2]]
21− ~zod:dojo> !>([|.(20)]:~)
22− [ p
23− [ %core
24− p=[%cube p=0 q=[%atom p=%n]]
25− q
26− [ p=%gold
27− q=[%cube p=0 q=[%atom p=%n]]
28− r=[p=[1 20] q={[p=%$ q=[%ash p=[%dtzy p=%ud q=20]]]}]
29− ]
30− ]
31− q=[[1 20] 0]
32− ]
33
18
34−In these slightly more complex cases we see a cell and a core expanded
19+In Hoon, dynamic type is static type compiled at runtime. This
35−to show their type information.
20+span-noun cell is generally called a `vase`.
21+
22+## Examples
23+
24+```
25+~zod:dojo> !>(1)
26+[#t/@ud q=1]
27+```
docs/programming/hoon/catalog/zap-wild/sem-spit.mddeleted−17
@@ -1,17 +0,0 @@
1−# `:spit`, `!;`, "zapsem" `{$spit p/twig q/twig}`
2−
3−`[type noun]` pair.
4−
5−`!;` is a natural rune that produces the product of twig `q` as a
6−`[type noun]` pair, with twig `p` serving as an example of the type.
7−
8−Regular form: *2-fixed*
9−
10−Examples:
11−
12− ~zod:dojo> !;(*type 1)
13− [[%atom p=%ud] 1]
14− ~zod:dojo> !;(*type [1 2])
15− [[%cell p=[%atom p=%ud] q=[%atom p=%ud]] 1 2]
16− ~zod:dojo> !;([%atom ''] ~doznec)
17− [[%atom 'p'] ~doznec]
docs/programming/hoon/catalog/zap-wild/tis-code.md+26−30
@@ -1,30 +1,26 @@
1+---
2+sort: 3
3+---
4+
1−# `:code`, `!=`, "zaptis" `$code p/twig}`
5+# `:code != "zaptis" {$code p/twig}`
2−
6+
3−Show nock.
7+Make the Nock formula for a twig.
4−
8+
5−`!=` is a natural rune that produces the formula of `p` as a Nock noun.
9+## Produces
6−
10+
11+The Nock generated by `p`.
12+
13+## Syntax
14+
7−Regular form: *1-fixed*
15+Regular: *1-fixed*.
8−
16+
9−Examples:
17+## Examples
10−
18+
19+```
11− ~zod:dojo> !=(20)
20+~zod:dojo> !=(20)
12− [1 20]
21+[1 20]
13− ~zod:dojo> !=(~zod)
22+~zod:dojo> !=(~zod)
14− [1 0]
23+[1 0]
15− ~zod:dojo> !=((add 2 2))
24+~zod:dojo> !=((add 2 2))
16− [8 [9 3.110.356 0 31] 9 2 [0 4] [7 [0 3] 1 2 2] 0 11]
25+[8 [9 3.110.356 0 31] 9 2 [0 4] [7 [0 3] 1 2 2] 0 11]
17− ~zod:dojo> !=(|=(a=@ [a a]))
26+```
18− [8 [1 0] [1 [0 6] 0 6] 0 1]
19− ~zod:dojo> !=(+(2))
20− [4 1 2]
21− ~zod:dojo> !=(.?(2))
22− [3 1 2]
23− ~zod:dojo> !=(.*(~ 2))
24− [2 [1 0] 1 2]
25− ~zod:dojo> !=(2)
26− [1 2]
27− ~zod:dojo> !=(.)
28− [0 1]
29− ~zod:dojo> !=(!!)
30− [0 0]
docs/programming/hoon/catalog/zap-wild/wut-need.md+22−11
@@ -1,16 +1,27 @@
1−# `:need`, `!?`, "zapwut", `{$need p/$@(p/@ {p/@ q/@}) q/twig}`
1+---
2+sort: 4
3+---
2
4
3−Restrict version.
5+# `:need !? "zapwut" {$need p/@ q/twig}`
4
6
5−Enforces a Hoon version restriction. XX help
7+Restrict Hoon version.
6
8
7−Regular form: *2-fixed*
9+## Produces
8
10
9−Examples: XX help
11+`q`, if `p` is greater than or equal to the Hoon kelvin version.
12+(Versions count down; the current version is 150.)
10
13
14+## Syntax
15+
16+Regular: *2-fixed*.
17+
18+## Examples
19+
20+```
11− ~zod:dojo> !?(264 (add 2 2))
21+~zod:dojo> !?(264 (add 2 2))
12− 4
22+4
13− ~zod:dojo> !?(164 (add 2 2))
23+~zod:dojo> !?(164 (add 2 2))
14− 4
24+4
15− ~zod:dojo> !?(163 (add 2 2))
25+~zod:dojo> !?(64 (add 2 2))
16− ! exit
26+! exit
27+```
docs/programming/hoon/catalog/zap-wild/zap-fail.md+23−20
@@ -1,23 +1,26 @@
1+---
2+sort: 1
3+---
4+
1−# `:fail`, `!!`, "zapzap" `{$fail $~}`
5+# `:fail, !! "zapzap" {$fail $~}`
2
6
3Crash.
7Crash.
4
8
5−Always causes a crash. Frequently used as sentinel, especially when you don't want the type system to
9+## Produces
6−give you type fails before you've written every possible branch of the
10+
7−computation.
11+Nothing. Always crashes, with span `%void`.
8−
12+
9−Regularm form: doesnt even accept input as it causes an immediate crash. XX???
13+## Syntax
10−
14+
15+`!!`
16+
17+## Discussion
18+
19+`%void` nests in every other span, so you can stub out anything with `!!`.
20+
11−Examples:
21+## Examples
12−
22+
13− ~zod:dojo> !!
23+```
14− ! exit
15− ~zod:dojo> =|(a=(unit) ?^(a !! %none))
16− %none
17− ~zod:dojo> :type; =|(a=(unit) ?^(a !! %none))
18− %none
19− %none
20− ~zod:dojo> ?+('a' !! %a 1, %b 2)
21− 1
22− ~zod:dojo> ?+('c' !! %a 1, %b 2)
24+~zod:dojo> !!
23− ! exit
25+! exit
26+```
docs/programming/hoon/twig/syntax.mddeleted−20
@@ -1,20 +0,0 @@
1−---
2−sort: 1
3−---
4−
5−# Hoon syntax
6−
7−Hoon's semantics are simple, but unusual. Hoon's syntax is
8−complex, and unusual. Sorry.
9−
10−An excuse: the normal human brain doesn't have hardware support
11−for math, but it does have hardware support for syntax. Learning
12−math is harder than it looks. Learning syntax is easier.
13−
14−An explanation: the Hoon syntax is trying to solve three serious
15−problems in functional syntax design.
16−
17−Read the [motivation](motivation) if you care; or go straight to
18−the actual [design](design).
19−
20−<list></list>
docs/programming/hoon/twig/syntax/design.mddeleted−297
@@ -1,297 +0,0 @@
1−# Design
2−
3−Because each twig stem has its own bulb, each has its own parser
4−rule. We'll describe these grammars as we go through the stems.
5−
6−But Hoon has a general syntax design with common principles and
7−regularities. We'll cover those here.
8−
9−## Glyphs and characters
10−
11−Hoon is a heavy punctuation user. To make ASCII great again,
12−we've mapped each punctuation glyph to a syllable:
13−
14−```
15− ace [1 space] gal < pal (
16− bar | gap [>1 space, nl] par )
17− bas \ gar > sel [
18− buc $ hax # sem ;
19− cab _ hep - ser ]
20− cen % kel { sig ~
21− col : ker } soq '
22− com , ket ^ tar *
23− doq " lus + tec `
24− dot . pam & tis =
25− fas / pat @ wut ?
26− zap !
27−```
28−
29−You don't need to memorize these glyph names, but it helps. Code
30−is often vocalized or subvocalized. "pal" is easier to say,
31−aloud or silently, then "left paren."
32−
33−Note that the list includes two separate whitespace forms: `ace`
34−for a single space, `gap` for 2+, comment or newline. Hoon
35−Besides `ace` versus `gap`, whitespace is not significant.
36−
37−Comments start with `::` and run to the end of the line. Hard
38−tab characters are illegal, and an 80-column right margin is
39−strongly encouraged. Really well-groomed Hoon uses a 55-column
40−code margin and puts a standard line comment at column 57.
41−
42−Hoon does not accept non-ASCII text in source files, except UTF-8
43−in quoted strings.
44−
45−## Tall and flat forms
46−
47−There are two kinds of Hoon expression syntax: *tall* and *flat*.
48−Most stems have both tall and flat forms. Tall twigs can contain
49−flat twigs, but not vice versa.
50−
51−Visually, a tall twig looks like a "statement" and a flat twig
52−like an "expression," preserving the attractive visual shape of
53−procedural code without the nasty side effects.
54−
55−## Regular and irregular forms
56−
57−Most stems have *regular forms*, which share a common design.
58−There is a regular flat form and a regular tall form; most stems
59−implement both. All tall forms are regular.
60−
61−Some twigs also have *irregular forms*, which follow no
62−principles at all. All irregular forms are flat.
63−
64−Some twigs (simple leafy ones) have *only* irregular forms.
65−
66−## Keywords versus runes
67−
68−A regular form starts with a *sigil*, which is either a
69−*keyword* or a *rune* -- at the programmer's choice.
70−
71−A *keyword* is `:` and then the stem label - eg, `:cons`.
72−
73−A *rune* is a pair of ASCII punctuation marks (a digraph) - eg,
74−`:-`. The first glyph in the rune indicates the category - eg,
75−`:` runes make cells. Runes can be pronounced by their glyphs or
76−by their stem -- for `:-`, you can say either "colhep" or "cons".
77−
78−Keywords may be less challenging for early learners. Rune style
79−is less cluttered and distracting for experienced programmers;
80−the system codebase is all in rune style. Beginners can start
81−with keywords and move to runes; start with runes and stick
82−with runes; or start with keywords and stick with keywords.
83−
84−Here's the FizzBuzz demo code, in idiomatic rune syntax. Compare
85−with the [original](../../demo).
86−
87−```
88− |= end/atom
89− =/ count 1
90− |- ^- (list tape)
91− ?: =(100 count) ~
92− :_ $(count (add 1 count))
93− ?: =(0 (mod count 15))
94− "FizzBuzz"
95− ?: =(0 (mod count 5))
96− "Fizz"
97− ?: =(0 (mod count 3))
98− "Buzz"
99− (text !>(count))
100−```
101−
102−## Tall regular form
103−
104−Tall regular form starts with the sigil, followed by a `gap`
105−(any whitespace except `ace`), followed by a bulb whose twigs are
106−separated by `gap`.
107−
108−There are four body subtypes: *fixed*, *running*, *jogging*, and
109−*battery*. Stems with a *fixed* number of subexpressions
110−self-terminate. For instance, `:if` has three subexpressions and
111−is self-terminating. Otherwise the twig is terminated by a
112−`gap`, then either `==` (*running* or *jogging*, most twigs) or
113−`--` (*battery*).
114−
115−The *running* body is a list of twigs. The *jogging* body is a
116−list of twig pairs, separated by a `gap`. The *battery* body is
117−a list of symbol-twig pairs, separated by a gap, prefixed by `++`
118−and then a gap.
119−
120−This definition is enough to parse. But the proper shape of the
121−whitespace gaps demands an informal convention.
122−
123−Whitespace design in Hoon is an art, not a science. It involves
124−both tall/flat mode switches and well-shaped gaps. (Hoon layout
125−could probably be done automatically with reasonable quality.
126−But it would at least take machine learning, not a rule engine.)
127−
128−There only two real *rules* in Hoon whitespace design: don't
129−go past 80 characters, and don't use (completely) blank lines.
130−Otherwise, if it looks good and is easy to read, it's good. But
131−the best way to learn the art is to do everything by convention
132−until you know what you're doing. Here are the conventions:
133−
134−### Conventions: *fixed*
135−
136−Bulbs with *fixed* fanout use "backstep" indentation, which slopes
137−backward and to the right by two spaces per line. The first
138−child is two spaces after the end of the sigil.
139−
140−Some *1-fixed*, *2-fixed*, *3-fixed* and *4-fixed* examples:
141−
142−```
143−|.
144−p
145−
146−=| p
147−q
148−
149−?: p
150− q
151−r
152−
153−%^ p
154− q
155− r
156−s
157−```
158−
159−The hope of backstep indentation is that the heaviest twigs are
160−at the bottom, keeping code flow vertical rather than diagonal.
161−Alternate, reversing
162−
163−### Conventions: *running*
164−
165−A *running* bulb (a simple child list) puts the first child two
166−spaces after the end of the sigil, and the following children
167−straight down:
168−
169−A *running* example:
170−
171−```
172−:* p
173− q
174− r
175− s
176− t
177−==
178−```
179−
180−### Conventions: *jogging*
181−
182−A *jogging* bulb (a list of child pairs) is like a running bulb,
183−but backsteps the head of the pair above the tail. Most jogging
184−twigs start with a *fixed* sequence; the first jogging pair is
185−below and two steps backward from the last fixed child.
186−
187−There are two jogging conventions: *flat* (pair on one line) and
188−*tall* (pair split across lines).
189−
190−A *flat jogging* example (preceded by *1-fixed* `p`)
191−
192−```
193−?- p
194− q r
195− s t
196− u v
197−==
198−```
199−
200−A *tall jogging* example (preceded by *1-fixed* `p`):
201−
202−```
203−?- p
204− q
205− r
206− s
207− t
208− u
209− v
210−==
211−```
212−
213−### Conventions: *battery*
214−
215−A *battery* bulb is a list of symbol-twig pairs, for the battery
216−of a core. A conventional example:
217−
218−```
219−|%
220−++ foo
221− p
222−++ bar
223− q
224−--
225−```
226−
227−## Flat regular form
228−
229−Flat regular form starts with the sigil, followed by `pal`
230−(`(`, left parenthesis), followed by a bulb whose subexpressions
231−are separated by `ace` (one space), followed by `par` (`)`, right
232−parenthesis).
233−
234−A twig in flat form, `:if`, `?:`, `{$if p/twig q/twig r/twig}`:
235−
236−```
237−:if(p q r)
238−
239−?:(p q r)
240−```
241−
242−The only exception is *jogging* bodies, in which subexpression
243−pairs are separated by commas:
244−
245−```
246−:make(foo bar 42, baz 55, moo 17)
247−```
248−
249−There is no flat regular form for *battery* bodies. Be tall.
250−
251−## Naming conventions
252−
253−Hoon does not enforce any rule on symbols, except that capitals
254−are not allowed (use kebab-case). However, a lot of system code
255−is written in using "lapidary" conventions that need explanation.
256−
257−Naming things is one of the hard problems in CS. Dodging this
258−problem is one of the reasons mathematicians use Greek letters,
259−not variable names. Meaningful names also interpose a verbal
260−interpretation, distracting at best and confusing at worst, on
261−the formula or algorithm. Greek letters are not *meaningful*,
262−but they are *memorable*. And their interpretation is defined by
263−the formula and nothing else.
264−
265−### Lapidary and ultralapidary
266−
267−In the *lapidary* naming style, labels are pronounceable
268−three-letter strings, usually CVC (consonant-vowel-consonant).
269−Sometimes they encode a mnemonic, but usually they are just
270−memorable. Labels are reused wherever the analogy seems
271−appropriate.
272−
273−In the *ultralapidary* naming style, labels are single letters,
274−starting in order of construction from `a`, or within a tuple
275−mold `p`. Hoon uses single-letter names for the same reason
276−Algol style languages pass arguments by order, rather than
277−keyword. Naming items by order makes sense when there are no
278−more than three or four; five is stretching it; six is too many.
279−
280−For example, when defining `add`, we want to name the operands
281−`a` and `b`. It's silly to call them `foo` and `bar`, let alone
282−`left-operand` and `right-operand`. The smaller the scale of an
283−algorithm, the simpler its names should be.
284−
285−### When in doubt, don't be lapidary
286−
287−This works in the other direction: namelessness doesn't scale.
288−Most normal code shouldn't use lapidary naming at all. (Everyone
289−agrees: there is *way* too much lapidary Hoon in Urbit.)
290−
291−Lapidary naming is only for *inherently simple code*: code that
292−both aspires to high elegance and clarity, and *is solving a
293−simple and elegant problem*.
294−
295−Given an ugly or complex problem, lapidary naming is a liability,
296−no matter the excellence of the programmer. When in doubt, use
297−long names and/or kebab-case.
docs/programming/hoon/twig/syntax/motivation.mddeleted−55
@@ -1,55 +0,0 @@
1−# Motivation
2−
3−Three common syntactic problems in functional languages that Hoon
4−is trying to fix: *terminator piles*, *indentation creep*,
5−and *feature/label confusion*.
6−
7−## Terminator piles
8−
9−*Terminator piles* are like Lisp's stacks of right parens. If a
10−syntax uses matching glyphs besides `)`, they get truly ugly.
11−Significant whitespace solves this problem but introduces others.
12−
13−Hoon has no terminator piles. Except for a 1-space / more-space
14−distinction, it has no significant whitespace.
15−
16−## Indentation creep
17−
18−*Indentation creep* is a problem caused by indentation conventions
19−where the indentation point is a function of expression tree
20−depth. It's true that short functions are better than long ones,
21−but long ones sometimes need to be written.
22−
23−A procedural block has a backbone of statements which flows
24−straight down. Most expressions are flat and of limited depth.
25−With some bulging, a long function flows *down* the page.
26−
27−A functional language lacks the expression/statement distinction.
28−So a long function means a deep tree. Given normal indentation
29−conventions, a long function wants to flow *down and across*.
30−This *diagonal* shape fits poorly into most editor windows.
31−
32−Thanks to backstep indentation (see below), Hoon programs are
33−shaped more or less like procedural programs.
34−
35−## Feature/label confusion
36−
37−*Feature/label confusion* is any syntax which makes it hard for
38−the eye to tell whether a token on the screen is a feature of the
39−language, or a label in the program. For example, in Lisp a
40−special form has the same syntax as a function call.
41−
42−The worst-case result of FLC is "DSL cancer". Every source file
43−is effectively written in its own domain-specific language. To
44−read a new file is to learn a new language -- "write-only code."
45−
46−A fixed reserved-word set, especially with syntax highlighting,
47−and especially with orthogonal grammar (in C, you don't write
48−`for(a b c)`), may not be too bad. User-level macros, operator
49−overloading, even excessive use of higher-order programming,
50−can all lead quickly to the tragedy of write-only code.
51−
52−Hoon has very weak FLC in keyword style, none in rune style.
53−It has no user-level macros or overloading. It does support
54−higher-order programming; write-only Hoon can certainly be
55−(and has been) written. But good Hoon style is to avoid it.