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