8# Urbyte 0: Setup and nouns
10This is the first post in our new Urbyte series.
12The Urbyte concept is that you, an ordinary programmer, not a
13kernel hacker or a Haskell magician (not that there's anything
14wrong with kernel hackers or Haskell magicians) can learn Hoon,
15Urbit's programming language.
17We're going to test this daring idea by teaching you Hoon, in
18easily digestible, byte-size chunks. Each post in the "Urbytes"
19series is designed to take about 15 minutes to consume. (Maybe
2010, if you're a kernel hacker or a Haskell magician.)
22We'll assume no knowledge of Urbit except for previous lessons.
23Ideally you have some basic familiarity with programming and can
24operate the Unix command line.
26We strongly encourage you to type in all the examples in each
27Urbyte. Urbytes are short, but not meant to be skimmed.
31First, [install Urbit](../../using/install/) on any
32Mac or Unix machine. On Windows, make a virtual Linux machine
33using VirtualBox or a similar tool.
35While you're downloading, read about Urbit ships:
39In the Urbyte exercises you'll be running what we call a "comet". A string starting with `~`, like `~zod`, is what Urbit
42A *ship* is one number which means four things: a network address,
43a cryptographic identity, a memorable name, and a single virtual
46We write this number in a base-256 format, where each digit is a
47syllable. Imagine if your phone number was a pronounceable
48string which sounded like a name in a foreign language. `~zod`
49is ship zero (making it a very important ship indeed!). An ordinary
50user-level ship is a "planet", a 32-bit number which becomes
51a four-syllable string, like `~talsur-todres`.
53*Comets*, at 128-bits or 16 syllables, are
54disposable identities that anyone can make for free to
55join the live network. Thus, comets make the ideal ship for
56playing around with Hoon, asking for help from other Urbit devs in [Talk](../../using/messaging/) if you
57need it, and showing off Urbit to your hacker friends.
61To create your comet, run:
70This will take a few minutes and will spin out a bunch of boot
71messages. At the end, you'll see something like:
74ames: on localhost, UDP 31337.
75http: live (insecure, public) on 8080
76http: live ("secure", public) on 8443
77http: live (insecure, loopback) on 12321
81To make sure everything is working, type `(add 2 2)` at the
82prompt, then hit return. Your screen now shows:
85ames: on localhost, UDP 31337.
86http: live (insecure, public) on 8080
87http: live ("secure", public) on 8443
88http: live (insecure, loopback) on 12321
94That's super awesome! You made your first noun! We'll make a
95few more in a second. First, quit Urbit with `ctrl-d`:
104You now have an Urbit image, or *pier*, in the `mycomet` directory.
105Right now the only thing in your pier is Urbit's system files:
108$ ls -a /path/to/mycomet
112Restarting uses almost the same command, but without `-c` (which
113means "create"). There are also fewer startup messages:
118ames: on localhost, UDP 31337.
119http: live (insecure, public) on 8080
120http: live ("secure", public) on 8443
121http: live (insecure, loopback) on 12321
125Note also that Urbit is an ACID database. You can stop it
126politely with `ctrl-d`, abruptly with `ctrl-z`, even violently with `kill
127-9`. None of these should cause Urbit to lose data. If you do
128manage to corrupt a pier, it's a bug; please let us know.
132You've already made a noun. Let's make another!
134*We won't show the `~palnul_nocser:dojo> ` prompt from here on out.
135We'll just show the echoed command.*
139~palnul_nocser:dojo> 42
150## Understanding nouns
152A value in Urbit is called a *noun*. A noun is either an *atom*
153(an unsigned integer of any size) or a *cell* (an ordered pair of
156In a sentence, a noun is a binary tree whose leaves are numbers.
157If you know Lisp, a noun is a minimalist S-expression. A noun
158can't have cycles (pointer loops). An implementation can use
159dags (shared subtrees), but the programmer can't detect them
160(there's no pointer equality test).
162The absence of graph cycles makes nouns much easier to save in
163persistent storage, send over the network, manage memory for
164(Urbit has no tracing garbage collector), etc.
166## Let's make some atoms
168So one kind of atom is a number. And the syntax (or at least one
169syntax) for a number is a decimal, like `42`. Seems legit.
171But just to be sure we understand this decimal thing, let's make
179Seems pretty straightforward.
186Why not try it again to make sure?
193Can we add another zero?
199Wat? When you tried to type that next zero and turn `420` into
200`4200`, Urbit actually *deleted the `0` and beeped at you.*
202But isn't an atom an unsigned integer of any size? It is.
203But the syntax is actually `4.200`:
212Just think of it as "4,200", written the German way with a dot.
214Why? Long decimals are unreadable. Human beings know this, so
215we group them in threes. For some historical reason, programming
216languages never copied this marvelous usability innovation.
218English notation for decimals is more common than German
219notation. Unfortunately, dot is URL-safe and comma isn't, and
220it's nice to have a regular syntax for atoms that's URL-safe.
222As for why Urbit deleted your zero: it parses your command line
223as you type, and rejects any characters after the parser stops.
225## Let's make some cells
227There's not much mystery about cells. A cell has a head and a
228tail, and puts brackets around them:
235`42` is the *head* and `420` is the *tail* of the cell. Cell
236syntax nests to the right:
249If you look at these nouns as binary trees, you see
252 [4 [42 420]] [[4 42] 420]
260Each number is an atom; each dot is a cell.
264And we're done! Type `|exit` to exit:
267~palnul_nocser:dojo> |exit
272## Questions and/or exercises
274And we're done with our very first Urbyte! Here are some questions to
275think about. These exercises are never mandatory, but they may
276be fun and/or interesting. Skip them if they're obvious.
278* What is the right way to represent common
279data structures as nouns?
281* A string? A *signed* integer?
282* A table or associative array?
284Just try to picture these structures in your head, or draw them on a piece of paper.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list