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