on master help sign in
Merge branch 'master-joshuareagan'

* master-joshuareagan: Formatting and additions: /docs/about/glossary/, /docs/hoon/demo/ /syntax/ /concepts/ Update reference.md Update concepts.md Adjusting `mint` description another round of edits in response to feedback Update concepts.md Edits in response to comments Update concepts.md Update concepts.md Update concepts.md Update concepts.md Update concepts.md No more `twig` Update demo.md Include the word "cell" minor adjustments

commit039466b60e4836619c55b0a7d38bf5540c942856 authorKeaton Dunsford <keaton@tlon.io> dateThu 14 Dec 2017, 02:28 (9 years ago) parentb641674e59df05
5 files changed+402−279
docs/about/glossary.md+192−104 docs/hoon/concepts.md+128−104 docs/hoon/demo.md+52−42 docs/hoon/reference.md+3−3 docs/hoon/syntax.md+27−26
docs/about/glossary.md+192−104
@@ -1,11 +1,10 @@
11---
2−navhome: '/docs'
3−next: True
2+navhome: /docs/
43sort: 3
5−title: Urbit glossary
4+title: Glossary
65---
76
8−# Urbit Glossary
7+# Glossary
98
109Urbit is renowned for its exotic terminology. Here's a simple overview
1110from the strange words in.
@@ -29,12 +28,13 @@ classed by the number of bits in their address:
2928
3029Any ship can be called an "urbit."
3130
32−> A summary [here](http://urbit.org/posts/address-space/).
33−
31+> You can find a longer-form summary here:
32+> [`urbit.org/posts/address-space/`](https://urbit.org/posts/address-space/).
33+
3434An Urbit identity is a string like `~firbyr-napbes`. It means nothing,
3535but it's easy to remember and say out loud. `~firbyr-napbes` is actually
36−just a 32-bit number, like an IP address, that we turn into a
37−human-memorable string.
36+just a 32-bit number (`3.237.967.392`, to be exact), like an IP address,
37+that we turn into a human-memorable string.
3838
3939Technically, an urbit is a secure digital identity that you own and
4040control with a cryptographic key, like a Bitcoin wallet. As in Bitcoin,
@@ -57,7 +57,7 @@ whose number is its bottom half. So the planet `~firbyr-napbes`,
5757`48.879`, whose parent is `~mun`, `0xef`, `239`. The parent of `~mun`
5858and all galaxies is `~zod`, `0`.
5959
60−##### <h5 id="pier">Pier</h5>
60+#### pier
6161
6262A ship's *pier* is its Unix directory. For planets the name of the pier is usually the planet name.
6363
@@ -65,60 +65,62 @@ A ship's *pier* is its Unix directory. For planets the name of the pier is usua
6565
6666> Nock is a Turing-complete, non-lambda combinator interpreter.
6767
68−- *atom*: any natural number
69−- *cell*: any ordered pair of nouns
70−- *formula*: a noun - a function at the Nock level
71−- *noun*: an *atom* or a *cell*
72−- *product*: a noun - the result of evaluating a formula against a
73− subject
74−- *subject*: a noun - the data against which a `formula` is
68+- <h6 id="-nock-noun">noun:</h6> an _atom_ or a _cell_
69+- <h6 id="-nock-atom">atom:</h6> any natural number
70+- <h6 id="-nock-cell">cell:</h6> any ordered pair of nouns
71+- <h6 id="-nock-subject">subject:</h6> a noun - the data against which a _formula_ is
7572 evaluated
73+- <h6 id="-nock-formula">formula:</h6> a noun - a function at the Nock level
74+- <h6 id="-nock-product">product:</h6> a noun - the result of evaluating a formula against a
75+ subject
7676
7777*See [Nock definition](../../nock/definition/).*
7878
79−### Hoon
79+## Hoon
8080
8181> Hoon is a strict, higher-order typed functional language that compiles
8282> itself to Nock.
8383
84−###### <h6 id="arm">arm:</h6> a named, functionally-computed attribute of a core
84+#### arm
85+
86+An _arm_ is a named, functionally-computed attribute of a [core](#-core).
8587
86−The *twig* of each arm is compiled to a Nock formula, with the
88+The [hoon](#-a-hoon) of each arm is compiled to a Nock formula, with the
8789enclosing `core` itself as the subject.
8890
8991There are two kinds of arms: *dry* and *wet*. Most arms are dry.
9092
91−- *dry*: normal, `++`, polymorphic by means of *variance*
93+- <h6 id="-arm-dry">dry:</h6> normal, `++`, polymorphic by means of *variance*
9294
9395For a dry arm, we ask, is the new payload compatible with the old
9496payload (against which the core was compiled)?
9597
96−- *wet*: unusual, `+-`, polymorphic by means of *genericity*
98+- <h6 id="-arm-wet">wet:</h6> unusual, `+-`, polymorphic by means of *genericity*
9799
98−A wet arm uses the twig as a macro. We create a new type analysis
100+A wet arm uses the hoon as a macro. We create a new type analysis
99101path, which works as if we expanded the callee with the caller's
100102context.
101103
102−*See [advanced types](/hoon/advanced)*.
104+*See [advanced types](../../hoon/advanced/)*.
103105
104−###### atom
106+#### atom
105107
106−A Hoon *atom* span describes a Nock atom, with two additional pieces
108+A Hoon _atom_ type describes a Nock atom, with two additional pieces
107109of metadata: an *aura*, and an optional constant.
108110
109−An atom span is *warm* or *cold* based on whether the constant exists.
111+An atom type is *warm* or *cold* based on whether the constant exists.
110112
111−- *warm*: if the constant is `~` (null), any atom is in the span
112−- *cold*: if the constant is `[~ atom]`, its only legal value is
113+- <h6 id="-atom-warm">warm:</h6> if the constant is `~` (null), any atom is in the type
114+- <h6 id="-atom-cold">cold:</h6> if the constant is `[~ atom]`, its only legal value is
113115 `atom`.
114116
115117*See [basic types](../../hoon/basic/#-atom-p-term-q-unit-atom)*
116118
117−###### aura: a soft atom type
119+#### aura
118120
119−*aura* is a name for an atom type. It represents the structure of an
120−atom in a string beginning with `@`. An aura may represent units,
121−print format, or other semantics. Its constraints on the value of an
121+An *aura* is a soft atom type. It represents the structure of an
122+atom in a string beginning with `@`. An aura may represent print
123+format or other semantics. Its constraints on the value of an
122124atom aren't enforced in any way.
123125
124126Two auras are compatible if one is a prefix of the other. You can
@@ -128,76 +130,133 @@ auras.
128130
129131Some common auras and their aliases:
130132
131−- *term* (`@tas`): a symbol - an atomic ASCII string which obeys
133+- <h6 id="-aura-term">term:</h6> (`@tas`): a symbol - an atomic ASCII string which obeys
132134 symbol rules: lowercase and digit only, infix hyphen ("kebab-case"),
133135 first character must be lowercase alphabetic.
134−- *cord* (`@t`): UTF-8 text, least-significant-byte first
135−- *char* (`@tD`): a character, a single unicode byte (for multi-byte
136+- <h6 id="-aura-cord">cord:</h6> (`@t`): UTF-8 text, least-significant-byte first
137+- <h6 id="-aura-char">char:</h6> (`@tD`): a character, a single unicode byte (for multi-byte
136138 characters and codepoints, see `@c`)
137139
140+You can find the list of all auras [here](../../hoon/twig/atom/sand/).
141+
138142*See [basic types](../../hoon/basic/#-atom-p-term-q-unit-atom)*.
139143
140−###### <h6 id="core">core:</h6> a code-data cell
144+#### core
141145
142−The code (*battery*) is the head, the data (*payload*) is the tail. All
143−code-data structures in normal languages (functions, objects, modules,
144−etc) become *core*s in Hoon.
146+A _core_ is a [cell](#-nock-cell) of `[code data]`, where we call the
147+code head the _battery_ and the data tail the _payload_. All code-data
148+structures in normal languages (functions, objects, modules, etc.)
149+become _core_s in Hoon.
145150
146−- <h6 id="battery">*battery*:</h6> the code of a core, a tree of *arms*
147−- <h6 id="payload">*payload*:</h6> the data in a core
151+- <h6 id="-core-battery">battery:</h6> the code of a core, a tree of *arms*
152+- <h6 id="-core-payload">payload:</h6> the data in a core
148153
149154*See [basic types](../../hoon/basic)*.
150155
151−###### face: a labeled subtree
156+#### face
157+
158+A Hoon _face_ is a labeled subtree.
152159
153160Hoon has no scope or symbol-table; there is only the subject. To
154161"declare" a "variable" is to construct a new subject:
155162`[name=value old-subject]`.
156163
157−A *face* is a span that wraps a name (`@tas`) around another span.
164+A face is a type that wraps a named symbol (of [aura](#-aura)
165+`@tas`) around another type.
158166
159167*See [advanced types](../../hoon/advanced/#-face-aliases-and-bridges)*.
160168
161−###### <h6 id="gate">gate:</h6> a function/lambda/closure
169+#### gate
162170
163−A *gate* is a core with one arm. To call a gate on an argument,
164−replace the sample (at [tree
165−address](../../hoon/twig/limb/limb/) `+6` in the core) with the
166−argument, and then compute the arm.
171+A _gate_ is a [core](#-core) with one [arm](#-arm) -- Hoon's closest
172+analog to a function/lambda/closure. To call a gate on an argument,
173+replace the sample (at [tree address](../../hoon/twig/limb/limb/) `+6`
174+in the core) with the argument, and then compute the arm.
167175
168−The payload of a gate has a shape of `{sample context}`.
176+The payload of a gate has a shape of `[sample context]`.
169177
170−- *sample*: the argument tuple
171−- *context*: the subject in which the gate was defined
178+- <h6 id="-gate-sample">sample:</h6> the argument tuple
179+- <h6 id="-gate-context">context:</h6> the subject in which the gate was defined
172180
173181*See [basic types](../../hoon/basic/#-core-p-span-q-map-term-span),
174−[`%-` or `:call`](../../hoon/twig/cen-call/hep-call/) (the `twig` for
175−calling a `gate`).*
182+[`%-` ("cenhep")](../../hoon/twig/cen-call/hep-call/) (the
183+[rune](#-rune) for calling a `gate`).*
184+
185+#### <h4 id="-a-hoon">hoon</h4>
186+
187+A [`hoon`](../../hoon/reference/) is the result of parsing a Hoon source
188+expression into an AST node. These AST nodes are nouns, like all
189+other Hoon data. Because every Hoon program is, in its entirety, a
190+single expression of Hoon, the result of parsing the whole thing
191+into an AST is a single `hoon`.
192+
193+A hoon is a tagged union of the form `[%tag data]`, where the tag
194+is a constant such as `%brts` (from the source [rune](#-rune) `|=`,
195+i.e. "bartis"), and is matched up with the appropriate type of data
196+(often more `hoon`s, from source subexpressions). For example, the
197+expression `:-(2 17)`, once parsed into an AST, becomes the following:
198+
199+```
200+[%clhp p=[%sand p=%ud q=2] q=[%sand p=%ud q=17]]
201+```
202+
203+The `%clhp` is produced from the rune `:-` (i.e. "colhep"). The 2 and
204+17 have each been parsed as `%sand`-tagged hoons, which represent
205+atoms (in this case each with an aura of `%ud`, i.e. unsigned
206+decimal).
176207
177−###### limb: attribute or variable reference
208+To parse Hoon source into a hoon AST, use `ream` on a `cord`
209+containing Hoon source. Try the following in [Dojo](../../using/shell):
210+
211+```
212+(ream ':+(12 7 %a)')
213+```
214+
215+The result should be:
216+
217+```
218+[%clls p=[%sand p=%ud q=12] q=[%sand p=%ud q=7] r=[%rock p=%tas q=97]]
219+```
220+
221+#### limb
222+
223+A _limb_ is an attribute or variable reference.
178224
179225To resolve a *limb* named "foo", the subject is searched depth-first,
180226head-first for either a face named "foo" or a core with an arm of
181227"foo". If a face is found, the result is a leg, if a core is
182228found, the result is the product of the arm.
183229
184−- *leg*: a subexpression, or subtree of the subject.
185−- *wing*: a list of limbs, searched from right to left (`a.b` means
230+- <h6 id="-limb-leg">leg:</h6> a subexpression, or subtree of the subject.
231+- <h6 id="-limb-wing">wing:</h6> a list of limbs, searched from right to left (`a.b` means
186232 `b` within `a`).
187233
188−*See [Limbs and wings](../../hoon/twig/limb)*
234+*See [Limbs and wings](../../hoon/twig/limb/)*
189235
190−###### loobean: a Hoon boolean
236+#### loobean
191237
192−`0` (`%.y`) is *yes*, `1` (`%.n`) is *no*.
238+A _loobean_ is a Hoon boolean. `0` (`%.y`) is *yes*, `1` (`%.n`) is *no*.
193239
194240> Why? It's fresh, it's different, it's new. And it's annoying. And it
195241> keeps you on your toes. And it's also just intuitively right.
196242
197−###### metal: a variance model
243+#### mark
244+
245+A _mark_ is Urbit's version of a MIME type, if a MIME type was an
246+executable specification. The mark is just a label that's used as a path
247+to a local source file in the Arvo filesystem. This source file defines
248+a core that can mold untrusted data, diff and patch, convert to other
249+marks, etc.
198250
199−Every core has a *metal* which defines its variance model (ie, the
200−properties of the span of a compatible core). The default is `gold`
251+If this sounds like magic, it isn't quite magic. There's no way
252+for different urbits to make sure they mean the same thing by the
253+same mark. However, when incompatibility happens, marks ensure
254+that we at least handle the situation in a predictable way.
255+
256+#### metal
257+
258+Every core has a _metal_ which defines its variance model (ie, the
259+properties of the type of a compatible core). The default is `gold`
201260(invariant).
202261
203262- `gold`: *invariant*
@@ -207,69 +266,98 @@ properties of the span of a compatible core). The default is `gold`
207266
208267*See [advanced types](/hoon/advanced)*.
209268
210−###### <h6 id="mold">mold:</h6> a type constructor / validator
269+#### mold
270+
271+A _mold_ is an idempotent [gate](#-gate) (function), accepting any noun,
272+and producing a range with a type, a set of nouns.
211273
212−A *mold* is an idempotent gate (function), accepting any noun, and
213−producing a range with a useful span.
274+Molds act as type constructor/validators in Hoon. An example: Arvo
275+[marks](#-marks) use Hoon's type system under the hood via molds to
276+validate untrusted network data.
214277
215−- *bunt*: the value a mold produces when normalizing its default
278+Here's some common mold terminology:
279+
280+- <h6 id="-mold-bunt">bunt:</h6> the value a mold produces when normalizing its default
216281 sample
217−- *icon*: the span of the mold's range
282+- <h6 id="-mold-icon">icon:</h6> the type of the mold's range
218283
219−*See [mold twigs](/hoon/twig/buc-mold/).*
284+*See [mold hoons](../../hoon/twig/buc-mold/).*
220285
221−###### nest: type compatibility test
286+#### nest
222287
223−*nest* is an internal function on two spans, which produces yes if the
224−set of nouns in the second span is provably a subset of the first.
288+`nest` is an internal Hoon function on two types which performs a type
289+compatibility test. `nest` produces yes if the
290+set of nouns in the second type is provably a subset of the first.
291+If `nest` produces no, the Hoon programmer will receive a `nest-fail`
292+error. This is one of the most commons errors in Hoon programming.
225293
226294*See [advanced types](../../hoon/advanced/)*.
295+*See [troubleshooting](../../hoon/troubleshooting/#-nest-fail)*.
227296
228−###### slot: a tree addressing scheme
297+#### rune
229298
230−Every cell has a head and a tail, each of which may be either an atom or
231−a cell. Therefore every noun is a binary tree. `+1` or `.` resolves to
232−the whole cell (technically this would work against an atom as well).
233−The head of `+n` is `+2n`, the tail is `+(2n+1)`.
299+A Hoon _rune_ is a pair of ASCII symbols used to begin a
300+[Hoon expression](#-a-hoon).
234301
235−###### <h6 id="span">span:</h6> an inferred type
302+For example, the rune [`?:`](../../hoon/twig/wut-test/col-if/) is
303+Hoon's most common conditional, a branch on a boolean test. The first
304+symbol in a rune represents a family of related runes. For example, the
305+[`?` family](../../hoon/twig/wut-test/) are all conditionals.
236306
237−A *span* defines a set (finite or infinite) of nouns and ascribes some
238−semantics to it. There is no Hoon syntax for a span; it is always
239−produced as the inferred range of an expression (*twig*).
307+The result of parsing a Hoon source expression&mdash;the rune, followed
308+by its respective children&mdash;into an AST node is simply called
309+a [`hoon`](#-a-hoon).
240310
241−*See [basic types](../../hoon/basic/#-type-span-and-mold).*
311+Runes have two syntactic forms, _tall_ and _flat_:
242312
243−###### <h6 id="twig">twig:</h6> a Hoon expression
313+- <h6 id="-rune-tall">tall:</h6> multiple lines, no parentheses, two or more spaces between
314+ tokens
244315
245−A *twig* is a Hoon expression. Specifically, twig is the mold for the
246−noun that a Hoon source expression compiles to. A twig is always a cell.
316+ Example:
247317
248−A twig has one of two forms: `{twig twig}`, which produces the ordered
249−pair of the two twigs, or a cell `{stem bulb}`, where `stem` is an
250−atomic symbol.
318+ ```
319+ ~zod:dojo> %+ add 2 2
320+ 4
321+ ```
322+- <h6 id="-rune-flat">flat:</h6> one line, parentheses, one space between tokens
251323
252−- <h6 id="stem">*stem*:</h6> an atomic symbol (`@tas`) - the name of a twig.
253−- <h6 id="bulb">*bulb*:</h6> The mold of the twig's contents.
324+ Example:
254325
255−Most twigs have a *regular form*, beginning with a *rune*. Some twigs
256−also have a syntactic *irregular form*; a few have *only* an *irregular form*.
326+ ```
327+ ~zod:dojo> %+(add 2 2) :: regular flat form
328+ 4
257329
258−- <h6 id="rune">*rune*:</h6> a pair of ASCII symbols used to begin a twig.
330+ ~zod:dojo> (add 2 2) :: irregular flat form
331+ 4
332+ ```
259333
260−For example, the rune [`?:`](../../hoon/twig/wut-test/col-if/) is
261−Hoon's most common conditional, a branch on a boolean test. The first symbol
262−in a rune represents a family of related `twig`s. For example, the
263−[`?` family](../../hoon/twig/wut-test/) are all conditionals.
334+Tall hoons can contain flat hoons, but not vice versa. All irregular
335+forms are flat.
264336
265−A regular twig has two syntactic forms, *tall* and *flat*:
337+*See [hoon concept](../../hoon/concepts/#-hoon),
338+[expressions](../../hoon/twig/), and [syntax](../../hoon/syntax/)*.
266339
267−- *tall*: multiple lines, no parentheses, two or more spaces between
268− tokens
269−- *flat*: one line, parentheses, one space between tokens
270340
271−Tall twigs can contain flat ones, but not vice versa. All irregular
272−forms are flat.
341+#### slot
342+
343+`slot` is the name for Hoon's tree addressing scheme.
344+
345+Every cell has a head and a tail, each of which may be either an atom or
346+a cell. Therefore every noun is a binary tree. `+1` or `.` resolves to
347+the whole cell (technically this would work against an atom as well).
348+The head of `+n` is `+2n`, the tail is `+(2n+1)`.
349+
350+#### type
351+
352+A Hoon _type_ defines a set (finite or infinite) of nouns and ascribes
353+some semantics to it. There is no direct syntax for defining
354+types; they are always defined by inference (i.e., by
355+[`mint`](#-mint)), usually using a constructor ([`mold`](#-mold)).
356+
357+All types are assembled out of base types defined in `++type`.
358+(Look up `++ type` in hoon.hoon for examples.) When the compiler
359+does type-inference on a program, it assembles complex types out
360+of the simpler built-in types.
361+
362+*See [basic types](../../hoon/basic/#-type-span-and-mold).*
273363
274−*See [twig concept](../../hoon/concepts/#-twig-expression),
275−[expressions](../../hoon/twig/), and [syntax](../../hoon/syntax/)*.
docs/hoon/concepts.md+128−104
@@ -10,25 +10,19 @@ title: Concepts
1010Usually, a new language is an improvement on one you already
1111know. If it isn't, it probably at least shares concepts with a
1212large family of relatives. These concepts come with words, like
13−*type* or *function*, that map cleanly onto its semantics.
13+_variable_ or _function_, that map cleanly onto its semantics.
1414
15−In Hoon we throw away almost all these words and invent new
15+In Hoon we throw away many of these words and invent new
1616ones, which mean almost the same things. But why?
1717
1818## Motivation
1919
2020Hoon has no close relatives. The normal jargon of programming
21−maps poorly onto its semantics. For example, although Hoon is a
22−typed language, the term "type" is not formally defined in Hoon.
23−"Type" is a great word, but Hoon has three separate concepts
24−which could comfortably claim it. We say "type" all the time; we
25−mean [`span`](#span), or `mold`, or `mark`, or possibly all three.
26−
27−Other common programming concepts used only informally in Hoon
28−are "function," "object," "event," "expression," "variable,"
29−"label," "closure", "environment," "scope," and probably a few
30−more. We do use these words informally, but we're always making
31−an analogy whose precision depends on context.
21+maps poorly onto its semantics. Some of the common concepts used
22+only informally in Hoon include "function," "object," "event,"
23+"variable," "label," "closure", "environment," "scope," and probably
24+a few more. We do use these words informally, but we're always
25+making an analogy whose precision depends on context.
3226
3327Hoon has concepts *like* all these abstractions, but they remain
3428*false cognates*. The closer an inexact cognate, the more
@@ -38,11 +32,11 @@ a few new words is a small price for avoiding this pain point.
3832## Concepts
3933
4034A few major Hoon concepts: `noun` (data), `nock` (interpreter),
41−[`mint`](#mint) (compiler), [`span`](#span) (type), [`twig`](#twig) (expression),
35+[`hoon`](#-hoon) (AST node), [`mint`](#-mint) (compiler), [`type`](#-type) (type),
4236`gate` (function), `mold` (constructor), `core` (object), `mark`
4337(protocol).
4438
45−### `noun` (data value)
39+### <a name="-noun">`noun`</a> (data value)
4640
4741A value in Hoon is called a `noun`. A noun is either a
4842unsigned integer of any size (`atom`), or an ordered pair of any
@@ -51,27 +45,29 @@ simpler (Lisp atoms effectively have dynamic type bits).
5145
5246The simplest noun syntax uses brackets, like `[a b]` for the cell
5347of `a` and `b`. Brackets nest right; `[a b c d]` is `[a [b [c
54−d]]]`. You'll also see braces: `{a b c d}`.
48+d]]]`.
5549
56−A noun list, by convention, points right and is zero-terminated.
57−Hoon uses tuples (improper nouns) more freely than Lisp; only
58−genuinely iterative structures are null-terminated lists.
50+A noun list, by convention, goes from left to right and is
51+null-terminated. That said, Hoon uses tuples (improper nouns) more
52+freely than Lisp; only genuinely iterative structures are
53+null-terminated lists.
5954
60−When an atom is used as a string (a `cord`), the bytes are always
61−UTF-8 in LSB first order. When you see `foo`, `$foo`, `%foo`,
62−etc, this refers to the integer `0x6f.6f66`, aka `7.303.014`.
63−(Hoon syntax breaks integer atoms in the German style.)
55+When an atom is used as a string (a `cord`), the bytes are always UTF-8
56+in LSB first order. When you see `'foo'` and `%foo`, this refers to the
57+integer `0x6f.6f66`, aka `7.303.014`. (Hoon syntax uses `.` to break
58+integer atoms in the German style, because `.`'s are URL-safe and `,`'s
59+aren't.)
6460
6561One common operation on nouns is `slot`, a tree addressing
6662scheme which maps an atom to a subtree. The whole noun is slot
6763`1`; the left child of `n` is `2n`, the right child `2n+1`.
6864
69−Nothing in Nock, Hoon or Urbit can create cycles in a noun or
65+Nothing in Nock, Hoon, or Urbit can create cycles in a noun or
7066detect pointer equivalence. Nouns are generally implemented
7167with reference counting, and have a lazy short Merkle hash to
7268help with equality testing and associative containers.
7369
74−### `nock` (interpreter)
70+### <a name="-nock">`nock`</a> (interpreter)
7571
7672Hoon compiles itself to the [Nock](../../nock) VM. Nock is a
7773Turing-complete, non-lambda combinator function. The function
@@ -82,17 +78,54 @@ it's still fun and useful to [learn more](../../nock).
8278
8379## Compilation concepts
8480
85−### <a name="mint">`mint`</a> (compiler)
81+### <a name="-hoon">`hoon`</a> (AST node)
8682
87−[`mint`](#mint) is the Hoon compiler. It maps a cell `{span twig}` to a
88−cell `{span nock}`, where a [`span`](#span) is a type, a [`twig`](#twig)
89−is a compiled expression (AST), and a `nock` is a Nock formula. `mint` accepts
90−a subject type and a source expression; it produces a product type
91−and an executable formula.
83+A [`hoon`](../reference) is the result of parsing a Hoon source
84+expression into an AST node. These AST nodes are nouns, like all
85+other Hoon data. Because every Hoon program is, in its entirety, a
86+single expression of Hoon, the result of parsing the whole thing
87+into an AST is a single `hoon`.
9288
93−Calculating the output type from the input type and the source
94−code is called "type inference." If you've used another typed
95−functional language, like Haskell, Hoon's type inference does the
89+A hoon is a tagged union of the form `[%tag data]`, where the tag
90+is a constant such as `%brts` (from the source `|=`, i.e. "bartis"),
91+and is matched up with the appropriate type of data (often more
92+`hoon`s, from source subexpressions). For example, the expression
93+`:-(2 17)`, once parsed into an AST, becomes the following:
94+
95+```
96+[%clhp p=[%sand p=%ud q=2] q=[%sand p=%ud q=17]]
97+```
98+
99+The `%clhp` is produced from the rune `:-` (i.e. "colhep"). The 2 and
100+17 have each been parsed as `%sand`-tagged hoons, which represent
101+atoms (in this case each with an aura of `%ud`, i.e. unsigned
102+decimal).
103+
104+To parse Hoon source into a hoon AST, use `ream` on a `cord`
105+containing Hoon source. Try the following in `dojo`:
106+
107+```
108+(ream ':+(12 7 %a)')
109+```
110+
111+The result should be:
112+
113+```
114+[%clls p=[%sand p=%ud q=12] q=[%sand p=%ud q=7] r=[%rock p=%tas q=97]]
115+```
116+
117+### <a name="-mint">`mint`</a> (compiler)
118+
119+[`mint`](#-mint) is the Hoon compiler. It maps a cell `[type hoon]`
120+to a cell `[type nock]`, where a [`type`](#-type) is type
121+information, a [`hoon`](#-hoon) is a parsed expression (AST), and a
122+`nock` is a Nock formula. `mint` takes as input the subject type
123+and a parsed source expression; it produces a product type and an
124+executable formula.
125+
126+Calculating the output type from the input `hoon` and subject type
127+is called "type inference". If you've used another typed functional
128+language, like Haskell, the Hoon compiler's type inference does the
96129same job but with less intelligence.
97130
98131Haskell infers backward and forward; Hoon only infers forward.
@@ -105,55 +138,39 @@ which makes your program more readable anyway. Also, the dumber
105138the compiler, the easier it is for a dumb human to understand
106139what the compiler is thinking.
107140
108−### <a name="twig">`twig`</a> (expression)
109−
110−A [`twig`](../reference) is a Hoon AST node, the result of parsing a
111−source expression. A Hoon source file encodes one twig.
141+The `mint` gate is inside the core `++ ut`, so call it using the
142+following syntax:
112143
113−As the noun that the parser produces, a twig is a tagged union of
114−the form `{stem bulb}`, where `stem` (the tag) is a `cord` which
115−controls the type of `bulb` (the data).
116−
117−As text, each twig has both regular and irregular syntax forms.
118−Regular syntax can be either *tall* or *flat*: multiline or
119−single-line. Irregular syntax is always flat. Tall twigs can
120−contain flat twigs, but not vice versa.
121−
122−Regular forms always start with a *sigil*, which is either a
123−*keyword* or a *rune* at the programmer's choice. A keyword is
124−the stem cord.
144+```
145+(~(<gate> <core> <arg 1>) <arg 2> <arg 3>)
146+```
125147
126−For most stems, tall regular form has no delimiter or terminator,
127−eliminating the `)))))` problem common in functional languages.
128−Hoon also uses an unusual "backstep" indentation pattern to
129−control left-margin drift.
148+The `<gate>` is mint, the `<core>` is `ut`, `<arg 1>` is the subject
149+type, and `<arg 3>` is the parsed Hoon AST (i.e., a `hoon` from the
150+last section). What's `<arg 2>`? It's another piece of type
151+information. As part of the type-checking process, mint checks that
152+the output type "nests" within the input type, i.e. that the output
153+type is a subset of the input type. If not, mint halts with a
154+`nest-fail` crash.
130155
131−Hoon is mildly whitespace-sensitive. It knows the difference
132−between no whitespace, one-space, and more-space. But all cases
133−of more-space mean the same thing. Flat syntax uses one-space,
134−tall syntax more-space.
156+Let's compile an example `hoon` from the last subsection into Nock.
157+Try the following in Dojo:
135158
136−As an example, the regular flat keyword syntax `:call(a b)` means
137−the same thing as the flat rune syntax `%-(a b)`, the tall
138−keyword syntax
159+(~(mint ut %noun) %noun [%clhp p=[%sand p=%ud q=2] q=[%sand p=%ud q=17]])
139160
140−```
141−:call a
142−b
143−```
144−or the tall rune syntax (here on one line, with double spaces):
145−```
146−%- a b
147−```
161+### <a name="-type">`type`</a> (type, as range)
148162
149−### <a name="span">`span`</a> (type, as range)
163+A `type` defines a set (finite or infinite) of nouns and ascribes
164+some semantics to it. There is no direct syntax for defining
165+types; they are always defined by inference (i.e., by
166+[`mint`](#-mint)), usually using a constructor (`mold`).
150167
151−A `span` is a Hoon type. It defines a set (finite or
152−infinite) of nouns and ascribes some semantics to it. There is
153−no syntax for spans; they are always defined by inference (ie, by
154−[`mint`](#mint)), usually using a constructor (`mold`).
168+All types are assembled out of base types defined in `++type`.
169+(Look up `++ type` in hoon.hoon for examples.) When the compiler
170+does type-inference on a program, it assembles complex types out
171+of the simpler built-in types.
155172
156−### `gate` (function)
173+### <a name="-gate">`gate`</a> (function)
157174
158175A `gate` is a Hoon function (lambda or closure). Other
159176constructs in Urbit are functions in the mathematical sense -- for
@@ -161,7 +178,7 @@ instance, a Nock formula is also a function. But a gate is not a
161178formula. The gate's argument is its *sample*; the result is its
162179*product*.
163180
164−### `core` (object)
181+### <a name="-core">`core`</a> (object)
165182
166183A `core` has no exact equivalent in conventional languages, but
167184the closest equivalent is an object. An object has methods; a
@@ -173,55 +190,62 @@ A gate is a special case of a core: a core with one arm, whose
173190name is the empty string. The shape of a core is `[battery
174191payload]`, where *battery* is a tree of Nock formulas
175192
176−### `mold` (type, as constructor)
193+### <a name="-mold">`mold`</a> (constructor)
177194
178195A `mold` is a constructor function (`gate`). Its sample is any
179196noun; its product is a structured noun. A mold is idempotent;
180197`(mold (mold x))` always equals `(mold x)`.
181198
182−Since there's no such thing as a [`span`](#span) declaration, we use molds
183−to define useful spans by example; we also use them to validate
184−untrusted network input.
199+Because there's no such thing as a [`type`](#-type) declaration,
200+we use molds to define useful types by example; we also use them
201+to validate untrusted network data.
185202
186−### `face` (named variable)
203+### <a name="-face">`face`</a> (named variable)
187204
188205In a conventional language, we have a scope, environment or
189−symbol table. Declaring a variable, like `var foo: atom`, adds
190−the name `foo` to the table with type `atom`.
206+symbol table. Declaring a variable, like e.g. `int foo = 3`,
207+adds the name `foo` to the table with type `int`.
191208
192−The Hoon equivalent is `:var foo atom`. But Hoon has a
193−homoiconic heap; there is no inscrutable scope or environment.
194−There is just the subject, which is one noun. To "declare a
195−variable" is to make a cell `[variable old-subject]`, and use it
196−as the subject of the [`twig`](#twig) below.
209+The Hoon analogue is `=/(foo atom 3 ...)`, where `foo` is a `face`
210+and `atom` is the type. But Hoon has a homoiconic heap; there is no
211+inscrutable scope or environment. There is just the subject, which
212+is one noun. To "declare a variable" is to make a cell
213+`[variable old-subject]`, and use that as the subject of the next
214+expression.
197215
198−So the labe[`twig`](#twig)l `foo` isn't a key in a symbol table; it's in the
199−type ([`span`](#span)) of the new value. It's not a variable named `foo`,
200−whose value is of type `atom`; it's a subtree of type `foo:atom`.
216+The label `foo` isn't a key in a symbol table; it's stored as a kind
217+of metadata, in the type ([`type`](#-type)) of the new value. It's not
218+a variable named `foo`, whose value is of type `atom`; it's a subtree
219+of type `foo:atom`.
201220
202−### <a name="limb">`limb`</a> (attribute or variable reference)
221+### <a name="-limb">`limb`</a> (attribute or variable reference)
203222
204−A [`limb`](../twig/limb/limb), like `foo`, is Hoon's equivalent of a variable
205−reference. A limb is a [`twig`](#twig); given a subject [`span`](#span),
206−[`mint`](#mint) resolves it to a Nock formula and a product [`span`](#span).
223+A [`limb`](../twig/limb/limb/), like `foo`, is Hoon's equivalent of a variable
224+reference. A limb is a [`hoon`](#-hoon); given a subject [`type`](#-type),
225+[`mint`](#-mint) resolves it to a Nock formula and a product [`type`](#-type).
207226
208−To resolve limb `foo`, [`mint`](#mint) searches the subject depth-first,
227+To resolve limb `foo`, [`mint`](#-mint) searches the subject depth-first,
209228head-first for either a `face` named `foo`, or a `core` with the
210229arm `foo`. If it finds a face, the product is a *leg*, or
211230subtree of the subject. If it finds a core, it computes the arm
212−formula with that core as the subject.
231+formula with that core as the subject. A limb can also be a slot
232+(direct tree address), like `+15`.
233+
234+The hoon compiler always resolves a limb to a tree axis lookup,
235+regardless of the kind of limb.
213236
214−A limb can also be a slot (direct tree address), like `+15`.
237+`boo:[foo=12 baz=23 boo=34]` evaluates to `34`.
238+`+6:[foo=12 baz=23 boo=34]` evaluates to `baz=23`.
215239
216−### `wing` ([`limb`](#limb) path)
240+### <a name="-wing">`wing`</a> ([`limb`](#-limb) path)
217241
218−A [wing](../twig/limb/wing) is a list of limbs. Like attribute references in a
219−conventional language, it uses the syntax `a.b.c`, but inside
220−out: Hoon `a.b.c` means "a within b within c", the equivalent of
221−`c.b.a` in any other language. All limbs but the last, here `a`,
242+A [wing](../twig/limb/wing/) is a list of limbs. Like attribute
243+references in a conventional language, it uses the syntax `a.b.c`,
244+but inside out: Hoon `a.b.c` means "a within b within c", the equivalent
245+of `c.b.a` in any other language. All limbs but the last, here `a`,
222246must be legs.
223247
224−### `mark` (type, as protocol name)
248+### <a name="-mark">`mark`</a> (type, as protocol name)
225249
226250A `mark` (really an Arvo concept, not a Hoon concept) is Urbit's
227251version of a MIME type, if a MIME type was an executable
docs/hoon/demo.md+52−42
@@ -1,6 +1,6 @@
11---
22navhome: /docs/
3−sort: 11
3+sort: 12
44next: true
55title: Demo
66---
@@ -11,68 +11,78 @@ Here's everyone's favorite whiteboard example, FizzBuzz. Each
1111line is commented with its number:
1212
1313```
14−|= end/atom :: 1
15−=/ count 1 :: 2
16−|- :: 3
17−^- (list tape) :: 4
18−?: =(end count) :: 5
19− ~ :: 6
20−:- :: 7
21− ?: =(0 (mod count 15)) :: 8
22− "FizzBuzz" :: 9
23− ?: =(0 (mod count 5)) :: 10
24− "Fizz" :: 11
25− ?: =(0 (mod count 3)) :: 12
26− "Buzz" :: 13
27− (pave !>(count)) :: 14
28−$(count (add 1 count)) :: 15
14+|= end=@ud :: 1
15+=/ count=@ud 1 :: 2
16+|- :: 3
17+^- (list tape) :: 4
18+?: =(end count) :: 5
19+ ~ :: 6
20+:- :: 7
21+ ?: =(0 (mod count 15)) :: 8
22+ "FizzBuzz" :: 9
23+ ?: =(0 (mod count 5)) :: 10
24+ "Fizz" :: 11
25+ ?: =(0 (mod count 3)) :: 12
26+ "Buzz" :: 13
27+ (scow %ud count) :: 14
28+$(count (add 1 count)) :: 15
2929```
3030
3131Hoon is a functional language. FizzBuzz is usually defined as a
32−side effect, but officially Hoon has no side effects. This code
33−will *return* a list of strings, not *print* a list of strings.
34−(Of course, if you run this code from the Urbit `dojo` (shell) you
35−will be able to see the product.)
32+side effect, but officially Hoon has no side effects. Accordingly,
33+this code will *produce* a list of strings, not *print* a list of
34+strings. (Of course, if you run this code from the Urbit
35+[_Dojo_](../../using/shell) (shell) you will be able to see the
36+product.)
3637
3738The code produces a list in which each item is either a number
3839(as a string), "Fizz", "Buzz", or "Fizzbuzz". The value `~` is
3940"null" and indicates the end of the list.
4041
41−Line 1 uses the `|=`
42−*[rune](https://urbit.org/docs/about/glossary#rune)* to define a
43−function of one argument, `end`, which is of the type `atom` (i.e.
44−an unsigned integer).
42+Line 1 uses the _[rune](../../about/glossary#rune)_ `|=` (pronounced
43+["bar-tis"](../syntax/#-glyphs-and-characters)) to define a function
44+that takes one argument, labelled `end`. The argument must be of the
45+type `@ud`, an unsigned decimal number.
4546
46−Line 2 declares a variable, `count`, with initial value `1`.
47+Line 2 uses the rune `=/` (pronounced "tis-fas") to declare a variable,
48+`count` of the unsigned decimal number type, with initial value `1`.
4749
48−Line 3 begins a loop.
50+Line 3 uses the rune `|-` ("bar-hep") to begin a loop.
4951
5052Line 4 defines the product of the loop as a list of `tape`s.
5153(A `tape` is a list of characters, one of Hoon's two string
52−types.) The `^-` rune is used for defining the product type the function
53−is to return.
54+types.) The rune `^-` ("ket-hep") is used for defining
55+the type of value the function must produce.
5456
55−Line 5 uses the `?:` rune, which is a conditional. This line
56−checks whether `count` equals `end`. If so, line 6 (and the
57−whole loop) returns the value `~`. The list is finished. If not,
58−line 7 produces an ordered pair. This pair will be: (a) the next
59−item in the list, determined by lines 8-14; and (b) the rest of
60−the list, determined by line 15.
57+Line 5 uses the rune `?:` ("wut-tis"), which is your classic "if, then,
58+else" conditional. The "if" clause uses the irregular form of the rune
59+`.=` ("dot-tis"), one of the fundamental [Nock](../../nock/definition)
60+instructions, to perform an equality test on the values of `count` and
61+`end`. This will produce either `%.y` (yes, the number 0) or `%.n`
62+(no, 1) and consequently compute the "then" or "else" clause
63+respectively.
64+
65+If the values of `count` and `end` are equal, line 6 (and the whole loop)
66+returns the value `~`. The list is finished.
67+
68+If not, line 7 uses the rune `:-` ("col-hep") to produce a 'cell', which
69+is an ordered pair of Hoon values. This pair will be: (a) the next item
70+in the list, determined by more `?:` conditionals in lines 8-14; and (b)
71+the rest of the list, determined by line 15.
6172
6273(a) The head of the pair is: (i) "FizzBuzz", or "Fizz", or
6374"Buzz", if the respective tests hit; otherwise, it's
6475(ii) the number in question, `count`. In case (ii), line 14
65−makes `count` into a `tape`, first by using `!>` to produce a
66−pair: runtime type of `count`, and `count` itself. `pave` is a
67−Hoon function that converts the type-value pair to a `tape`
68−(like C `sprintf()`).
76+uses the Hoon standard library function `++scow` to take the value of
77+`count`, of type `@ud`, and pretty-print it as a `tape`.
6978
7079(b) The tail of the pair&mdash;the rest of the output list&mdash;is
71−produced at line 15, which uses `$()` to repeat the loop (like
72−Clojure `recur`), with `count` incremented.
80+produced at line 15, which uses the irregular `$()` syntax for the rune
81+`%=` ("cen-tis") to repeat the loop set above (with the `|-` in line 3)
82+with `count` incremented.
7383
7484You can test this code by mounting your home desk with
75−`|mount %` from the dojo; saving the above code as
85+`|mount %` from the Dojo; saving the above code as
7686`home/gen/fizzbuzz.hoon` in your Urbit
77−[pier](https://urbit.org/docs/about/glossary#pier); then typing
87+[pier](../../about/glossary#pier); then typing
7888`+fizzbuzz 100` in the dojo.
docs/hoon/reference.md+3−3
@@ -1,12 +1,12 @@
11---
22navhome: /docs/
33sort: 21
4−title: Twig reference
4+title: Expression reference
55---
66
7−# Twig reference
7+# Expression reference
88
9−#### A catalog of all twig stems:
9+#### A catalog of expressions:
1010
1111<div class="book">
1212
docs/hoon/syntax.md+27−26
@@ -111,10 +111,10 @@ line comment at column 57.
111111## Expressions and Runes
112112
113113Each regular Hoon expression begins with a
114−[rune](https://urbit.org/docs/about/glossary#rune). A rune is a pair
114+[rune](../about/glossary/#-rune). A rune is a pair
115115of ASCII punctuation marks (a digraph)&mdash;e.g., `:-`. The first
116116glyph in the rune indicates the category&mdash;e.g., `:` runes make
117−[cells](https://urbit.org/docs/about/glossary#cell) (i.e., ordered
117+[cells](../about/glossary/#-cell) (i.e., ordered
118118pairs). We pronounce runes using their glyph names&mdash;for `:-`,
119119we say "colhep".
120120
@@ -126,29 +126,30 @@ kind of subexpressions depend on the rune used.
1261263
127127```
128128
129−This twig uses `:-` to produce a cell: `[25 3]`. There are always two
129+This Hoon uses `:-` to produce a cell: `[25 3]`. There are always two
130130subexpressions following the `:-` in syntactically correct Hoon code,
131131the first of which, when evaluated, becomes the *head* (i.e., the left)
132132and the second of which becomes the *tail* (i.e., the right).
133133
134−Hoon expressions are sometimes called
135−[twigs](https://urbit.org/docs/about/glossary#twig). You'll find that
136−Hoon code has a tree-like structure, so you can think of the various
137−expressions as twigs of the tree. The subexpressions following the
138−rune are sometimes called the *children* of that twig.
134+Hoon expressions are just called
135+[hoons](../about/glossary/#-twig), because a rune's subexpression can itself
136+be a Hoon expression (i.e. another rune). You'll start to see this tree-like,
137+recursive structure the more you program in Hoon. You can think of one Hoon
138+file being composed of multiple hoons. The subexpressions following the
139+rune are sometimes called the *children* of that hoon.
139140
140141## Tall and flat forms
141142
142143There are two kinds of Hoon expression syntax: *tall* and *flat*.
143−Most runes can be used in both tall and flat twigs. Tall twigs can
144−contain flat twigs, but not vice versa.
144+Most runes can be used in both tall and flat twigs. Tall hoons can
145+contain flat hoons, but not vice versa.
145146
146147The `:-` expression in the last subsection was in tall form. Here's
147148the flat equivalent:
148149
149150`:-(25 3)`
150151
151−Visually, a tall twig looks like a "statement" and a flat twig
152+Visually, a tall hoon looks like a "statement" and a flat hoon
152153like an "expression," preserving the attractive visual shape of
153154procedural code without the nasty side effects.
154155
@@ -172,7 +173,7 @@ follow, and returns a boolean. Above is the tall, regular form of
172173
173174`=(22 23)`
174175
175−Some twigs have *only* irregular forms.
176+Some hoons have *only* irregular forms.
176177
177178## Tall regular form
178179
@@ -182,14 +183,14 @@ that are the number and types of subexpressions appropriate for
182183that rune. Each subexpression is separated from its neighboring
183184subexpressions by a `gap`.
184185
185−Let's call everything in the twig after the initial rune the twig
186+Let's call everything in the hoon after the initial rune the hoon
186187*body*. There are four body subtypes: *fixed*, *running*, *jogging*,
187−and *[battery](https://urbit.org/docs/about/glossary#battery)*.
188+and *[battery](../about/glossary/#-battery)*.
188189
189190Runes with a *fixed* number of subexpressions self-terminate. For
190191instance, the `:-` and `.=` runes each have two subexpressions
191−and are self-terminating. Otherwise the twig is terminated by both
192−a `gap`, then either `==` (*running* or *jogging*, most twigs) or
192+and are self-terminating. Otherwise the hoon is terminated by both
193+a `gap`, then either `==` (*running* or *jogging*, most hoons) or
193194`--` (*battery*).
194195
195196The *running* body has a list of *children* (i.e., subexpressions).
@@ -217,7 +218,7 @@ until you know what you're doing. Here are the conventions:
217218
218219Twig bodies with *fixed* fanout use "backstep" indentation, which
219220slopes backward and to the right by two spaces per line. The first
220−twig child is two spaces after the end of the rune.
221+hoon child is two spaces after the end of the rune.
221222
222223Some *1-fixed*, *2-fixed*, *3-fixed* and *4-fixed* examples:
223224
@@ -238,12 +239,12 @@ r
238239s
239240```
240241
241−In optimal usage of backstep indentation, the most complicated twigs
242+In optimal usage of backstep indentation, the most complicated hoons
242243are at the bottom, keeping code flow vertical rather than diagonal.
243244
244245### Conventions: *running*
245246
246−A *running* twig body (a simple child list) puts the first child two
247+A *running* hoon body (a simple child list) puts the first child two
247248spaces after the end of the rune, and the following children straight
248249down:
249250
@@ -260,7 +261,7 @@ A *running* example:
260261
261262### Conventions: *jogging*
262263
263−A *jogging* twig body (a list of child pairs) is like a running
264+A *jogging* hoon body (a list of child pairs) is like a running
264265body, but with a pair of children on each line, separated by
265266two spaces. Most jogging bodies start with a *fixed* sequence;
266267the first jogging pair is below and two steps backward from the
@@ -295,9 +296,9 @@ A *tall jogging* example (preceded by *1-fixed* `p`):
295296### Conventions: *battery*
296297
297298A *battery* body has a list of symbol-child pairs, for the
298−[battery](https://urbit.org/docs/about/glossary#battery)
299+[battery](../about/glossary/#-battery)
299300of a
300−[core](https://urbit.org/docs/about/glossary#core). A
301+[core](../about/glossary/#-core). A
301302conventional example:
302303
303304```
@@ -318,7 +319,7 @@ Flat regular form starts with the rune, followed by `pal`, `(`
318319are separated by `ace` (one space), followed by `par`, `)` (right
319320parenthesis).
320321
321−A twig in flat form, `:if`, `?:`, `{$if p/twig q/twig r/twig}`:
322+A hoon in flat form, `?:` ("wutcol"), `[%if p=hoon q=hoon r=hoon]`:
322323
323324`?:(p q r)`
324325
@@ -355,7 +356,7 @@ appropriate.
355356
356357In the *ultralapidary* naming style, labels are single letters,
357358starting in order of construction from `a`, or within a tuple
358−[mold](https://urbit.org/docs/about/glossary#mold) `p`. Hoon
359+[mold](../about/glossary/#-mold) `p`. Hoon
359360uses single-letter names for the same reason Algol style
360361languages pass arguments by order, rather than keyword. Naming
361362items by order makes sense when there are no more than three or
@@ -384,7 +385,7 @@ long names and/or kebab-case.
384385
385386If you came all this way to learn how to write apps, you're all
386387set. This is about all you need to know to start getting your
387−hands dirty. Refer back here or to the [standard library](../../hoon/library) when
388−needed, but for now, move on to [Arvo](../../arvo) to continue learning.
388+hands dirty. Refer back here or to the [standard library](../library/) when
389+needed, but for now, move on to [Arvo](../../arvo/) to continue learning.
389390
390391If, however, good enough is *not* enough, feel free to dive deeper: