on 8e080d6 help sign in
34 lines 1.4 kB history raw
1---
2sort: 4
3next: true
4---
6# Data model: `noun`
8A value in Hoon is called a `noun`. A noun is either a unsigned
9integer of any size (`atom`), or an ordered pair of any two
10nouns (`cell`). In other words, a noun is a binary tree whose
11leaves are unsigned integers.
13Nouns are a Nock concept; there is no Nock syntax; so there is no
14general noun syntax. But nouns are usually written with square
15brackets associating right; `[a b c]` means `[a [b c]]`. In Hoon
16we also see `{a b c}`, a constructor (`mold`) for `[a b c]`.
18Nouns are almost like Lisp's S-expressions, but S-expressions
19have dynamic type tags in atoms. Nouns can lose this feature
20because they're designed to sit under a static type system. For
21the same reason, nouns tend to be tuple-centric where Lisp is
22list-centric. Lisp `(a b c)` as a noun is `[a b c 0]`; Nock `[a
23b c]` is Lisp `(a . b . c)`.
25Nouns are immutable and acyclic. A naive implementation uses
26reference counting and needs no tracing GC. There is no test for
27pointer equality as in Lisp. But indirect nouns have a lazily
28computed short hash, so nonduplicates have O(1) comparison cost.
30All kinds of atomic values can be and are stored as atoms:
31unsigned integers, signed integers (with sign bit low), dates,
32floats, UTF-8 strings (LSB first), even whole files. Again,
33a static type system is essential; an atom is not usable or even
34printable if we don't know what it means.