@@ -1,267 +0,0 @@
4−title: Urbyte 0: setup, nouns
17−This is the first post in our new Urbyte series.
19−The Urbyte concept is that you, an ordinary programmer, not a
20−kernel hacker or a Haskell magician (not that there's anything
21−wrong with kernel hackers or Haskell magicians) can learn Hoon,
22−Urbit's programming language.
24−We're going to test this daring idea by teaching you Hoon, in
25−easily digestible, byte-size chunks. Each post in the "Urbytes"
26−series is designed to take about 15 minutes to consume. (Maybe
27−10, if you're a kernel hacker or a Haskell magician.)
29−We'll assume no knowledge of Urbit except for previous lessons.
30−Ideally you have some basic familiarity with programming and can
31−operate the Unix command line.
33−We strongly encourage you to type in all the examples in each
34−Urbyte. Urbytes are short, but not meant to be skimmed.
38−First, [install Urbit](http://urbit.org/docs/using/install/) on any
39−Mac or Unix machine. On Windows, make a virtual Linux machine
40−using VirtualBox or a similar tool.
42−While you're downloading, read about Urbit ships:
46−In the Urbyte exercises you'll be running what we call a "fake
47−`~zod`." A string starting with `~`, like `~zod`, is what Urbit
50−A ship is one number which means four things: a network address,
51−a cryptographic identity, a memorable name, and a single virtual
52−computer. We write this number in a base-256 format, where each
55−`~zod` is ship zero, making it a very important ship indeed.
56−Your "fakezod" thinks it's `~zod`, but no one can talk to it.
58−This is not the true Urbit experience, of course. But it's
59−ideal if all you want to do is play around with Hoon. If you
60−have a real urbit ship, of course, you can use that instead.
64−To create a fakezod, run:
67−$ urbit -FI ~zod -c myzod
70−This will take about 30 seconds and spin out a bunch of boot
71−messages. At the end, you'll see:
74−ames: on localhost, UDP 31337.
75−http: live (insecure, public) on 8080
76−http: live ("secure", public) on 8443
77−http: live (insecure, loopback) on 12321
81−To make sure everything is working, type `(add 2 2)` at the
82−prompt, then hit return. Your screen now shows:
85−ames: on localhost, UDP 31337.
86−http: live (insecure, public) on 8080
87−http: live ("secure", public) on 8443
88−http: live (insecure, loopback) on 12321
94−That's super awesome! You made your first noun! We'll make a
95−few more in a second. First, quit Urbit with `^D`:
104−You now have an Urbit image, or *pier*, in the `myzod` directory.
105−Right now the only thing in your pier is Urbit's system files:
112−Restarting uses almost the same command, but without `-c`. There
113−are also fewer startup messages.
116−$ urbit -FI ~zod myzod
118−ames: on localhost, UDP 31337.
119−http: live (insecure, public) on 8080
120−http: live ("secure", public) on 8443
121−http: live (insecure, loopback) on 12321
125−Note also that Urbit is an ACID database. You can stop it
126−politely with `^D`, abruptly with `^Z`, even violently with `kill
127−-9`. None of these should cause Urbit to lose data. If you do
128−manage to corrupt a pier, it's a bug; please let us know.
132−We already made a noun. Let's make another. (We won't show the
133−`~zod:dojo> ` prompt in future, just the echoed command.)
147−## Understanding nouns
149−A value in Urbit is called a *noun*. A noun is either an *atom*
150−(an unsigned integer of any size) or a *cell* (an ordered pair of
153−In a sentence, a noun is a binary tree whose leaves are numbers.
154−If you know Lisp, a noun is a minimalist S-expression. A noun
155−can't have cycles (pointer loops). An implementation can use
156−dags (shared subtrees), but the programmer can't detect them
157−(there's no pointer equality test).
159−The absence of graph cycles makes nouns much easier to save in
160−persistent storage, send over the network, manage memory for
161−(Urbit has no tracing garbage collector), etc.
163−## Let's make some atoms
165−So one kind of atom is a number. And the syntax (or at least one
166−syntax) for a number is a decimal, like `42`. Seems legit.
168−But just to be sure we understand this decimal thing, let's make
176−Seems pretty straightforward.
183−Why not try it again to make sure?
190−Can we add another zero?
196−Wat? When you tried to type that next zero and turn `420` into
197−`4200`, Urbit actually *deleted the `0` and beeped at you.*
199−But isn't an atom an unsigned integer of any size? It is.
200−But the syntax is actually `4.200`:
209−Just think of it as "4,200", written the German way with a dot.
211−Why? Long decimals are unreadable. Human beings know this, so
212−we group them in threes. For some historical reason, programming
213−languages never copied this marvelous usability innovation.
215−English notation for decimals is more common than German
216−notation. Unfortunately, dot is URL-safe and comma isn't, and
217−it's nice to have a regular syntax for atoms that's URL-safe.
219−As for why Urbit deleted your zero: it parses your command line
220−as you type, and rejects any characters after the parser stops.
222−## Let's make some cells
224−There's not much mystery about cells. A cell has a head and a
225−tail, and puts brackets around them:
232−`42` is the *head* and `420` is the *tail* of the cell. Cell
233−syntax nests to the right:
246−If you look at these nouns as binary trees, you see
249− [4 [42 420]] [[4 42] 420]
257−Each number is an atom; each dot is a cell.
259−## Questions and/or exercises
261−And we're done with our very first Urbyte! Here's a question to
262−think about. These exercises are never required, but they may
263−be fun and/or interesting.
265−The question today is: what is the right way to represent common
266−data structures as nouns? A linked list? A string? A *signed*
267−integer? A table or associative array?