on 65048fe help sign in
54 lines 1.7 kB history raw
1---
2sort: 8
3next: true
4title: Expression: twig
5---
7# Expression: `twig`
9A `twig` is an AST node: the noun that the Hoon compiler makes
10when it parses a source expression.
12The definition of `twig` is the definition of Hoon. So let's
13define the syntax and semantics of Hoon, a twig at a time. But
14first, basic twig anatomy.
16## Twig anatomy and jargon
18A twig is a tagged union (`book`) with the form `{stem bulb}`,
19where the `stem` is an atomic symbol. The bulb for each stem has
20its own type, which varies by stem. (Compare with Lisp, where
21every AST node is a tag and a list of child nodes.)
23There are no user-level macros. All stems are built into Hoon.
24Most stems are implemented as internal macros, however.
26The bulb is usually a tuple, sometimes a list or map. An element
27of this structure is a *subexpression*.
29Usually a subexpression is itself a `twig`; sometimes it's an
30`@tas` (symbol) or a `wing` (reference path).
32## Moss versus wood
34Solely for clarity, we use the type alias `moss` for twigs whose
35product is used as a mold. A `moss` is just a twig, both in
36syntax and semantics; again, the difference is how we use it.
38Twigs are described as *mossy* and *woody*; an example of X is
39the woody form of X, a mpld producing X is its woody form. For
40instance, `$foo` (mossy) is a mold whose product is always `%foo`
41(woody). (Obviously, wood is *yang* and moss is *yin*, so we
42can also say "yang foo" or "yin foo".)
44## Twig categories
46Fortunately, the twigs fit neatly into clear categories which
47match their rune prefix. Read forward by category:
49<div><list/></div>
51## Twig structure
53The full Core Hoon `twig`. Note that this is simplified, but
54everything useful can still be done in Core.