@@ -6,122 +6,10 @@ next: true
6# Atoms and strings
6# Atoms and strings
8The simplest expressions in every language are constants:
8The simplest expressions in every language are constants:
9−atoms and strings. This section
9+atoms, strings, paths. (Strings aren't all constants per
10+se, because they have interpolations.)
11−Some of these constructs aren't quite constants, li
15−(Some of the "constant" syntax below can interpolate dynamic
14+<list dataPreview="true" className="runes"></list>
16−twigs. When it does, it obviously isn't constant at all.)
20−Recall the `$atom` span, `{$atom p/aura q/(unit @)}`.
22−Each atom constant syntax implies an `aura`, which is just a
23−textual symbol. The aura is used indiscriminately to convey
24−physical units, semantic interpretations, parsing syntax, and/or
25−printing syntax. It's soft type and can be manually overridden.
27−To write an aura, we generally borrow the atomic mold syntax,
28−such as `@ud` for the unsigned decimal.
31−in its irregular mold syntax, such as
32−`@ud`. The syntax for the
41− {$knit p/(list $@(@ {$~ p/seed}))}
42− {$path p/(list (each @tas seed))
48−All Hoon constants are irregular; they have no rune form. The
49−stems described below are `$rock` (cold / constant), `$sand`
50−(warm / open), `$knit` (iterative string), and `$path` (Unix
55−Recall the `$atom` span, `{$atom p/aura q/(unit @)}`.
57−Each atom constant syntax implies an aura. Note that the aura is
58−used indiscriminately to convey physical units, semantic
59−interpretations, parsing syntax, and/or printing syntax.
63−### Cold or warm, single or arbitrary
65−A span is a set of nouns; an `$atom` span contains either one
66−atom (*cold*) or all atoms (a *warm*).
68−In general, the `%` prefix is added to indicate coldness. `42`
69−is warm and `%42` is cold. `@tas` symbols (which start with `%`
70−already, see below) are always cold.
72−### Unsigned integer: `@ud`, `@ux`, `@uw`.
74−Unsigned integers are broken into groups of 3 for decimals, and 4
75−for non-decimals, separated German style by `.`; `420` plus `999`
78−A hex (`@ux`) favorite is `0xcafe.babe`.
80−`0w` is base64: `0-9`, `a-z` + 10, `A-Z` + 36, `-` and `~`. For
81−giant numbers, you can put whitespace/newlines after the `.`.
83−### Boolean and null: `@f`, `@n`.
85−Booleans in Hoon (`@f`) are `&` for yes (`@f`) and `|` for no.
86−Remember that `&` is `0` and `|` is `1` (which is why we say
87−"yes" and "no" rather than "true" and "false").
89−Nil (aura `@n`) is `~` (with the value `0`).
93−`'text'` in single quotes, `@t`, is a UTF-8 string LSB first.
95−`%symbol`, `@tas`, containing only `a-z`, `0-9` and `-`, starting
96−with `a-z`, and ending with `a-z0-9`, is a valid symbolic name.
98−`%$` is an empty `@tas`, ie, `0` with span `@tas`.
100−### Signed integer: `@sd`
102−Signed integers (`@sd`) are encoded with sign bit *low*. This
103−means we need a special syntax for positive signed integers,
104−since their atomic value can't be their unsigned value. For
105−example, `-3` is the atom `7`, whereas `--3` encodes to `6`.
109−Hoon also has list-shaped strings (less compact, more editable).
110−Use double quotes: `"hello, world"`. The mold is `tape` or
111−`(list char)`, where `char` is a UTF-8 byte.
113−Within a quoted string, interpolate with `{}`: `"hello, {(weld
114−"wo" "rld")}"`. It's also worth noting that `<`, `gar`, and `>`,
115−`gal` (angle brackets) stringify any twig: `"hello, {<mul 6
116−7>}"`. (Obviously, an interpolated string is not a constant.)
120−The path `/foo/bar/baz` is the constant `[%foo %bar %baz ~]`.
121−A path can be dynamically interpolated with `[]`:
124−/foo/[:(if & %bar %rab)]/baz`
127−equals `/foo/bar/baz`.