back

visualizing nouns as binary trees

“a noun is an atom or a cell of two nouns.”


an atom is a whole number, from zero to infinity.

you can use atoms to represent lots of things, like alphabet letters or dates or booleans.

a cell is a pair of nouns.

notice the circular definition: nouns may contain nouns.


in other words: a noun is a binary tree of integers.


for simplicity, in the following examples,
an “atom” is always a single alphabet letter,
like 'e' or 'n'.


an atom: the letter 't'

't'
1
t

the red number 1 indicates the “axis” that 't' lives at in the tree.

an “axis” represents a unique location in the binary tree.

the node at the top of the tree is always axis 1.


a cell of atoms: 't' and 'o'

['t' 'o']
1.
2
t
3
o

't' lives at axis 2, 'o' lives at axis 3.

axis 1 does not have an atom.

atoms will always live at at the leaves of the binary tree, never in the middle.


the values of a cell can be another cell.

['t' ['o' 'n']]
1.
2
t
3.
6
o
7
n

here's one with lots of cells inside of cells.

[['a' [['b' 'q'] 'c']] ['z' 'u']]
1.
2.
4
a
5.
10.
20
b
21
q
11
c
3.
6
z
7
u

if you try to write a cell with more than 2 values in it, it's called a “tuple”.

hoon will automatically break apart the elements of a tuple into cells: always moving right to left.

here's a tuple with 4 elements.

['t' 'o' 'n' 'e']
1.
2
t
3.
6
o
7.
14
n
15
e

notice: even though the hoon code for the tuple looks “flat”, the resulting structure is a binary tree.


we can also build tuples and cells with the “col” runes.

:+ 't' 'o' ['n' 'e']
1.
2
t
3.
6
o
7.
14
n
15
e
:^ 't' 'o' 'n' 'e'
1.
2
t
3.
6
o
7.
14
n
15
e

a “list” is a tuple ending in the empty symbol (~).

['t' 'o' 'n' 'e' ~]
1.
2
t
3.
6
o
7.
14
n
15.
30
e
31
~

a list of letters is called a “tape”.

it can be written as text with double quotes around it.

"tone"
1.
2
t
3.
6
o
7.
14
n
15.
30
e
31
~

let's turn “tone” into “stone” by wrapping the tape in a new cell.

['s' "tone"]
1.
2
s
3.
6
t
7.
14
o
15.
30
n
31.
62
e
63
~

now let's try to turn “tone” into “tones”.

["tone" 's']
1.
2.
4
t
5.
10
o
11.
22
n
23.
46
e
47
~
3
s

wait, that's not right!
's' should not be at axis 3.

when adding to the end of a list, we can't use cells or the col runes because the tape is a tree!

we need to traverse down the tree, find the ~ at the end, then insert the 's'.

we can use snoc from the list functions to add to the end of list.

(snoc "tone" 's')
1.
2
t
3.
6
o
7.
14
n
15.
30
e
31.
62
s
63
~

notice:

  • lists always extend down and to the right

  • lists always end in the empty symbol.


but lists are not the only things we can represent with binary trees.

everything in urbit is a binary tree!

for example, “sets” are an efficient data structure which makes sure there is only one of each unique element.

silt will take a list of elements and turn it into a set.

(silt "book")
1.
2
b
3.
6.
12
k
13.
26
~
27
~
7.
14
o
15.
30
~
31
~

notice:

  • 'o' is only in the tree once.

  • the shape of the tree does not only go down and to the right


there's much more to learn about urbit nouns...

for example: nock is a ruleset for how to interpret a noun as a computer program.

but hopefully this helps visualize the basic shape of what runs urbit:
for now and forever.


you can see the hoon code that generated this document here.

and if you want to learn how to make your own visualizations with code and prose, install hawk on your urbit today.