on master help sign in
Merge pull request #152 from keatondunsford/push-to-www-again
c8fbfe0Galen Wolfe-Pauly
docs/learn.mddeleted−24
@@ -1,24 +0,0 @@
1−---
2−navhome: /docs/
3−sort: 2
4−---
5−
6−# Learn
7−
8−Learn Hoon from the ground up through our in-house Urbyte series, or delve into the great doc efforts by some of our community members.
9−
10−#### Urbytes
11−
12−<list dataPath="/docs/learn/urbyte/" />
13−
14−#### Community docs
15−
16−* `~master-morzod` -
17−[docs](http://micnus-tarwyl-haltem-linhut--dilhul-talbes-wolnyx-lasbud.urbit.org/docs/), [`fora` post](https://urbit.org/fora/posts/~2016.12.25..06.35.44..a1ec~/)
18−
19−* `~hidduc-posmeg` -
20−[docs](https://fosnut-dandut.urbit.org/pages/hidducs-notes/tutorial), [`fora` post](https://urbit.org/fora/posts/~2017.2.12..21.54.40..6fde~/)
21−
22−* `~palfun-foslup` - [Urbit by Doing](https://github.com/Fang-/Urbit-By-Doing)
23−
24−* `@knubie` - [Learning Hoon](https://github.com/knubie/learning-hoon)
docs/learn/community.mddeleted−20
@@ -1,20 +0,0 @@
1−---
2−navhome: /docs/
3−next: true
4−title: Community docs
5−sort: 2
6−---
7−
8−# Community docs
9−
10−* The `~master-morzod`
11−[docs](http://micnus-tarwyl-haltem-linhut--dilhul-talbes-wolnyx-lasbud.urbit.org/docs/),
12−and [`fora`](https://urbit.org/fora/posts/~2016.12.25..06.35.44..a1ec~/) post.
13−
14−* The (formerly) `~hidduc-posmeg`
15−[docs](https://fosnut-dandut.urbit.org/pages/hidducs-notes/tutorial),
16−and [`fora`](https://urbit.org/fora/posts/~2017.2.12..21.54.40..6fde~/) post.
17−
18−* [Urbit by Doing](https://github.com/Fang-/Urbit-By-Doing), by `~palfun-foslup`.
19−
20−* [Learning Hoon](https://github.com/knubie/learning-hoon), by `knubie`.
docs/learn/urbyte.mddeleted−13
@@ -1,13 +0,0 @@
1−---
2−navhome: /docs/
3−next: true
4−title: Urbytes
5−sort: 1
6−---
7−
8−# Urbytes
9−
10−Learn Hoon in short, self-contained, bottom-up tutorials.
11−A work in progress. Still ideal for the complete newbie.
12−
13−<list/>
docs/learn/urbyte/0.mddeleted−281
@@ -1,281 +0,0 @@
1−---
2−navhome: /docs/
3−sort: 1
4−next: true
5−title: Setup and nouns
6−---
7−
8−# Urbyte 0: Setup and nouns
9−
10−This is the first post in our new Urbyte series.
11−
12−The Urbyte concept is that you, an ordinary programmer, not a
13−kernel hacker or a Haskell magician (not that there's anything
14−wrong with kernel hackers or Haskell magicians) can learn Hoon,
15−Urbit's programming language.
16−
17−We're going to test this daring idea by teaching you Hoon, in
18−easily digestible, byte-size chunks. Each post in the "Urbytes"
19−series is designed to take about 15 minutes to consume. (Maybe
20−10, if you're a kernel hacker or a Haskell magician.)
21−
22−We'll assume no knowledge of Urbit except for previous lessons.
23−Ideally you have some basic familiarity with programming and can
24−operate the Unix command line.
25−
26−We strongly encourage you to type in all the examples in each
27−Urbyte. Urbytes are short, but not meant to be skimmed.
28−
29−## Install
30−
31−First, [install Urbit](http://urbit.org/docs/using/install/) on any
32−Mac or Unix machine. On Windows, make a virtual Linux machine
33−using VirtualBox or a similar tool.
34−
35−While you're downloading, read about Urbit ships:
36−
37−## Ships
38−
39−In the Urbyte exercises you'll be running what we call a "comet". A string starting with `~`, like `~zod`, is what Urbit
40−calls a *ship*.
41−
42−A *ship* is one number which means four things: a network address,
43−a cryptographic identity, a memorable name, and a single virtual
44−computer.
45−
46−We write this number in a base-256 format, where each digit is a
47−syllable. Imagine if your phone number was a pronounceable
48−string which sounded like a name in a foreign language. `~zod`
49−is ship zero (making it a very important ship indeed!). An ordinary
50−user-level ship is a "planet", a 32-bit number which becomes
51−a four-syllable string, like `~talsur-todres`.
52−
53−*Comets*, at 128-bits or 16 syllables, are
54−disposable identities that anyone can make for free to
55−join the live network. Thus, comets make the ideal ship for
56−playing around with Hoon, asking for help from other Urbit devs in [`:talk`](http://urbit.org/docs/using/messaging/) if you
57−need it, and showing off Urbit to your hacker friends.
58−
59−## Create and restart
60−
61−To create your comet, run:
62−
63−```
64−$ cd ~
65−$ mkdir urbit
66−$ cd urbit
67−$ urbit -c mycomet
68−```
69−
70−This will take a few minutes and will spin out a bunch of boot
71−messages. At the end, you'll see something like:
72−
73−```
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
78−~palnul_nocser:dojo>
79−```
80−
81−To make sure everything is working, type `(add 2 2)` at the
82−prompt, then hit return. Your screen now shows:
83−
84−```
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
89−> (add 2 2)
90−4
91−```
92−~palnul_nocser:dojo>
93−
94−That's super awesome! You made your first noun! We'll make a
95−few more in a second. First, quit Urbit with `ctrl-d`:
96−
97−```
98−> (add 2 2)
99−4
100−~palnul_nocser:dojo>
101−$
102−```
103−
104−You now have an Urbit image, or *pier*, in the `mycomet` directory.
105−Right now the only thing in your pier is Urbit's system files:
106−
107−```
108−$ ls -a /path/to/mycomet
109−./ ../ .urb/
110−```
111−
112−Restarting uses almost the same command, but without `-c` (which
113−means "create"). There are also fewer startup messages:
114−
115−```
116−$ urbit mycomet
117−[...]
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
122−~palnul_nocser:dojo>
123−```
124−
125−Note also that Urbit is an ACID database. You can stop it
126−politely 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
128−manage to corrupt a pier, it's a bug; please let us know.
129−
130−## Let's make a noun
131−
132−You've already made a noun. Let's make another!
133−
134−*We won't show the `~palnul_nocser:dojo> ` prompt from here on out.
135−We'll just show the echoed command.*
136−
137−
138−```
139−~palnul_nocser:dojo> 42
140−42
141−```
142−
143−You'll see:
144−
145−```
146−> 42
147−42
148−```
149−
150−## Understanding nouns
151−
152−A 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
154−any two nouns).
155−
156−In a sentence, a noun is a binary tree whose leaves are numbers.
157−If you know Lisp, a noun is a minimalist S-expression. A noun
158−can't have cycles (pointer loops). An implementation can use
159−dags (shared subtrees), but the programmer can't detect them
160−(there's no pointer equality test).
161−
162−The absence of graph cycles makes nouns much easier to save in
163−persistent storage, send over the network, manage memory for
164−(Urbit has no tracing garbage collector), etc.
165−
166−## Let's make some atoms
167−
168−So one kind of atom is a number. And the syntax (or at least one
169−syntax) for a number is a decimal, like `42`. Seems legit.
170−
171−But just to be sure we understand this decimal thing, let's make
172−some atoms:
173−
174−```
175−> 4
176−4
177−```
178−
179−Seems pretty straightforward.
180−
181−```
182−> 42
183−42
184−```
185−
186−Why not try it again to make sure?
187−
188−```
189−> 420
190−420
191−```
192−
193−Can we add another zero?
194−
195−```
196−> 420
197−```
198−
199−Wat? When you tried to type that next zero and turn `420` into
200−`4200`, Urbit actually *deleted the `0` and beeped at you.*
201−
202−But isn't an atom an unsigned integer of any size? It is.
203−But the syntax is actually `4.200`:
204−
205−```
206−> 4.200
207−4.200
208−> (mul 42 100)
209−4.200
210−```
211−
212−Just think of it as "4,200", written the German way with a dot.
213−
214−Why? Long decimals are unreadable. Human beings know this, so
215−we group them in threes. For some historical reason, programming
216−languages never copied this marvelous usability innovation.
217−
218−English notation for decimals is more common than German
219−notation. Unfortunately, dot is URL-safe and comma isn't, and
220−it's nice to have a regular syntax for atoms that's URL-safe.
221−
222−As for why Urbit deleted your zero: it parses your command line
223−as you type, and rejects any characters after the parser stops.
224−
225−## Let's make some cells
226−
227−There's not much mystery about cells. A cell has a head and a
228−tail, and puts brackets around them:
229−
230−```
231−> [42 420]
232−[42 420]
233−```
234−
235−`42` is the *head* and `420` is the *tail* of the cell. Cell
236−syntax nests to the right:
237−
238−```
239−> [4 [42 420]]
240−[4 42 420]
241−
242−> [4 42 420]
243−[4 42 420]
244−
245−> [[4 42] 420]
246−[[4 42] 420]
247−```
248−
249−If you look at these nouns as binary trees, you see
250−
251−```
252− [4 [42 420]] [[4 42] 420]
253− . .
254− / \ / \
255− 4 . . 420
256− / \ / \
257− 42 420 4 42
258−```
259−
260−Each number is an atom; each dot is a cell.
261−
262−## And we're done
263−
264−And we're done! Type `|exit` to exit:
265−
266−```
267−~palnul_nocser:dojo> |exit
268−%drum-exit
269−$
270−```
271−
272−## Questions and/or exercises
273−
274−And we're done with our very first Urbyte! Here's a question to
275−think about. These exercises are never mandatory, but they may
276−be fun and/or interesting. Skip them if they're obvious.
277−
278−The question today is: what is the right way to represent common
279−data structures as nouns? A linked list? A string? A *signed*
280−integer? A table or associative array? Just try to picture
281−these structures in your head, or draw them on a piece of paper.
docs/learn/urbyte/1.mddeleted−369
@@ -1,369 +0,0 @@
1−---
2−navhome: /docs/
3−sort: 2
4−next: true
5−title: Atoms, auras, types
6−---
7−
8−# Urbyte 1: Atoms, auras, types
9−
10−Thanks for reading Urbyte 0! In Urbyte 1, we'll look a little
11−more deeply at atoms and other simple noun types.
12−
13−Let's restart our engines:
14−
15−```
16−$ urbit mycomet
17−[...]
18−ames: on localhost, UDP 31337.
19−http: live (insecure, public) on 8080
20−http: live ("secure", public) on 8443
21−http: live (insecure, loopback) on 12321
22−~palnul_nocser:dojo>
23−```
24−
25−## What's in an atom?
26−
27−It seems limiting to have only one kind of atom, the unsigned
28−decimal. How are signed integers represented? Symbols?
29−Floating-point values? Dates? IP addresses? Even just hex?
30−
31−Lisp's S-expression, with its own cells and atoms, is very
32−similar to Hoon's nouns. But languages in the Lisp family mark
33−each atom with a dynamic tag that defines the atom's meaning.
34−These tags are effectively dynamic types.
35−
36−Hoon also tracks the meaning of atoms. But Hoon is statically
37−typed, so an atom description is obviously a type. An atomic type
38−in Hoon is called an *aura*. The aura syntax is just an ASCII
39−string starting with `@`, like `@ud` for unsigned decimal.
40−
41−Hoon has a wide (but not extensible) variety of atom syntaxes.
42−Each syntax for an atom produces an appropriate predefined aura.
43−And Hoon's printer can invertibly print any aura Hoon can parse.
44−Because atoms make great path nodes and paths make great URLs,
45−all regular atom syntaxes use only URL-safe characters.
46−
47−## Examples
48−
49−With the dojo command `? expression`, you tell the dojo to print
50−both the product of the expression, and the product's type.
51−
52−Let's type in some aura examples:
53−
54−### Unsigned integers
55−
56−```
57−> 42
58−42
59−
60−> ? 42
61− @ud
62−42
63−
64−> ? 0x42
65− @ux
66−0x42
67−
68−> ? (add 0x42 42)
69− @
70−108
71−
72−> ? `@ud`0x42
73− @ud
74−66
75−
76−```
77−
78−So decimal is aura `@ud`, hexadecimal is `@ux`. Note the cast
79−syntax, which lets us change the type of an atom, converting hex
80−`0x42` to a decimal `66`.
81−
82−An aura is soft type. The programmer can always insist on how
83−to interpret an atom. Hoon doesn't have "dependent types"; it
84−can't enforce any constraints the aura puts on the atom's value.
85−
86−### Signed integers
87−
88−```
89−> -7
90−-7
91−
92−> ? -7
93− @sd
94−
95−> --7
96−--7
97−
98−> ? --7
99− @sd
100−--7
101−
102−> ? (sum:si -7 --7)
103− @s
104−--0
105−
106−> `@ud`-7
107−13
108−
109−> `@ud`--7
110−14
111−```
112−
113−`--7` means "positive 7." `+7` might have been better, but `+`
114−is not URL-safe.
115−
116−Hoon needs `--` to distinguish positive signed numbers because
117−Hoon's type system doesn't feed back into its parser. The
118−expression itself needs to control whether it's `@sd` or `@ud`.
119−
120−With unlimited atom width, traditional sign extension makes no
121−sense. The sign bit is the low bit. Even atoms are positive,
122−odd atoms are negative.
123−
124−And Hoon has no overloading or type detection; we need to use a
125−different function to add signed integers. We'll always choose
126−slightly clunkier syntax in exchange for much simpler semantics.
127−
128−### Symbols
129−
130−```
131−> ? 'Ürbit'
132− @t
133−'Ürbit'
134−
135−> ? `@ux`'Ürbit'
136− @ux
137−0x7469.6272.9cc3
138−
139−> ? ~~Ürbit
140− @t
141−'Ürbit'
142−
143−> ? ~.urbit
144− @ta
145−~.urbit
146−
147−> ? `@ux`'foo'
148− @ux
149−0x6f.6f66
150−```
151−
152−The `@t` aura is UTF-8 text, with the first byte low. Again,
153−Hoon doesn't actually have the power to check statically that
154−your UTF-8 is valid. Auras don't tell you what an atom is, just
155−what you think it is.
156−
157−The familiar single-quote syntax for `@t` is an irregular form of
158−the more unusual `~~` prefix. The `~.` prefix, aura `@ta`, is
159−restricted to lowercase ASCII (a great common denominator). Of
160−course, `~` is URL-safe and `'` is not.
161−
162−### Dates, floats, IP addresses...
163−
164−```
165−> ? now
166− @da
167−~2016.7.11..01.32.04..2c0d
168−
169−> ? ~h6
170− @dr
171−~h6
172−
173−> `@ux`~h6
174− @ux
175−0x5460.0000.0000.0000.0000
176−
177−> ? (add ~h6 now)
178− @
179−170.141.184.502.236.089.414.812.327.632.537.911.296
180−
181−> `@da`(add ~h6 now)
182−~2016.7.11..07.32.28..842f
183−
184−> ? .3.14
185− @rs
186−.3.14
187−
188−> ? .127.0.0.1
189− @if
190−.127.0.0.1
191−```
192−
193−`@da` is a 128-bit absolute date (64 bits for fractions of a
194−second, 64 bits for seconds); `@dr` is a relative date; `@rs` is
195−a single-precision IEEE real; `@if` is an IPv4 address. This is
196−not all Hoon's aura syntax, just a good range of examples.
197−
198−`(add ~h6 now)` is a good example of the use and limits of
199−the aura system. Unlike the signed-integer sum, offsetting a
200−date can use plain atomic addition. But the product of `add` is
201−a flavorless atom with no aura, `@`. So we have to cast it back
202−to an absolute date `@da`.
203−
204−## Auras explained
205−
206−Does an aura represent the units of the atom, its syntax, its
207−semantics, its constraints?
208−
209−Any or all of the above. Programmers can even use their own aura
210−strings, which nothing in Hoon recognizes. The set of syntaxes
211−that Hoon knows how to parse and/or print is fixed. But there
212−are plenty of good reasons to use your own user-defined auras.
213−
214−If your program uses both fortnights and furlongs, Hoon will not
215−parse a user-defined fortnight syntax. It will not print furlongs
216−in the dojo. But the type system will keep you from accidentally
217−passing a furlong to a function that expects a fortnight.
218−
219−Hoon does interpret the aura string in one way: auras specialize
220−to the right. For example, `@u` is any unsigned integer; `@ux`
221−is an unsigned integer that likes to be printed as hex.
222−
223−Hoon's typechecker lets you go up or down the specialization
224−ladder. It complains if you try to move across. For example,
225−`@u` can silently convert into `@ux` or `@ux` into `@u`, but
226−turning `@ud` into `@ux`, `@ux` into `@da`, etc, requires an
227−explicit cast.
228−
229−## Constants, symbols, loobeans and null
230−
231−An atom type isn't just an aura. There's another choice: the
232−type can be *general* and contain all atoms (like the types we've
233−seen above), or *constant* and contain just one atom.
234−
235−A type describes a set of values. While auras may informally
236−describe a format for which not all atoms are valid, any atom can
237−be cast into the aura whether valid or invalid. But in a
238−constant, the type contains just one atom.
239−
240−The regular syntax for an atomic constant is just to put `%` in
241−front of the constant. Like:
242−
243−```
244−> ? 42
245− @ud
246−42
247−
248−> ? %42
249− $42
250−%42
251−
252−> ? %~h6
253− $~h6
254−%~h6
255−```
256−
257−The `$` on the type indicates the constant. Note that constants
258−still have auras; `~h6` (6 hours) is still a `@dr`.
259−
260−## Common irregulars
261−
262−There are a few special forms worth learning early: symbols,
263−null, loobeans, and of course ships:
264−
265−```
266−> ? %foo
267− $foo
268−%foo
269−
270−> `@ux`%foo
271−0x6f.6f66
272−
273−> .n
274−%.n
275−
276−> |
277−%.n
278−
279−> .y
280−%.y
281−
282−> &
283−%.y
284−
285−> `@ud`&
286−0
287−
288−> ~
289−~
290−
291−> `@ud`~
292−0
293−
294−> ? ~zod
295− @p
296−~zod
297−
298−> `@ux`~forseg-bolbyn
299−0x885e.8af9
300−```
301−
302−`%symbol` is a constant with aura `@tas` (text, ASCII, symbol).
303−The symbol rules, which are enforced by the Hoon parser but not
304−(as we've discussed) the type system: a symbol is lowercase with
305−infix hyphens ("kebab-case").
306−
307−Loobeans are not true and false, but yes (`.y` or `&`) and no
308−(`.n` or `|`). This is because *yes is zero and no is one*.
309−This makes sense at a certain mathematical level, though it
310−was probably a mistake from a practical perspective.
311−
312−`~` is Hoon's nil: constant `0`, aura `@n`.
313−
314−And of course, `@p` is the phonemic base used for ship names.
315−(It's useful for any kind of memorable number.)
316−
317−## Cells and types
318−
319−Naturally, all these atoms fit neatly into cells, and retain
320−their types within the cells.
321−
322−```
323−> ? [~h6 [.3.14 %foo] 0xdead.beef]
324− {@dr {@rs $foo} @ux}
325−[~h6 [.3.14 %foo] 0xdead.beef]
326−
327−> `*`[~h6 [.3.14 %foo] 0xdead.beef]
328−[398.449.671.992.126.314.905.600 [1.078.523.331 7.303.014] 3.735.928.559]
329−```
330−
331−Another fun trick is to cast any noun to the `*` type, ie,
332−generic noun. We then know nothing about the noun, so we print
333−all its atoms as decimals.
334−
335−## And we're done
336−
337−And we're done! Type `|exit` to exit:
338−
339−```
340−~palnul_nocser:dojo> |exit
341−%drum-exit
342−$
343−```
344−
345−## Questions and/or exercises
346−
347−As always, these questions are optional and only for fun.
348−
349−We didn't include anywhere near all Hoon's auras or syntaxes in
350−this lesson. It's just a set of examples.
351−
352−Try using the dojo's magic error erasure to stumble around the
353−rest of Hoon's atom syntax. Any string that can't be extended
354−into a valid expression will be trimmed back, with a beep, until
355−it can. Return will beep if the expression is not complete.
356−This feedback is harmless and does not use an electric shock.
357−It enables stochastic reinforcement learning of Hoon syntax.
358−
359−If `~h6` is six hours, how do you write forty-five minutes? Two
360−days, six hours and forty-five minutes?
361−
362−What would you expect the syntax for double-precision float to
363−be? What about base64?
364−
365−Does an absolute date have to include every zillisecond, or can
366−it be pruned to a day or a year?
367−
368−If there's an IP syntax, what about bitcoin addresses? What
369−other auras do you think should be supported?
docs/learn/urbyte/2.mddeleted−495
@@ -1,495 +0,0 @@
1−---
2−navhome: /docs/
3−sort: 3
4−title: Subject-oriented programming
5−---
6−
7−# Urbyte 2: Subject-oriented programming
8−
9−Thanks for reading Urbytes 0 and 1! In Urbyte 2, we'll take
10−nouns for granted and have some real fun with them.
11−
12−Let's restart our engines:
13−
14−```
15−$ urbit mycomet
16−[...]
17−ames: on localhost, UDP 31337.
18−http: live (insecure, public) on 8080
19−http: live ("secure", public) on 8443
20−http: live (insecure, loopback) on 12321
21−~palnul_nocser:dojo>
22−```
23−
24−## Welcome to the dojo
25−
26−Wait, where are we?
27−
28−We're playing in the Urbit `:dojo`. The dojo is sort of like a
29−cross between a Lisp REPL and the Unix shell. (If you know the
30−Unix shell, the Urbit command line has the same history model and
31−Emacs editing commands.)
32−
33−The dojo has its own command language, which is a superset of
34−Hoon. Any Hoon expression is a command. But not all commands
35−are expressions.
36−
37−(The dojo is not the only command-line app on your Urbit. By
38−default there is one other, `:talk`. Since you're on a fakezod,
39−you can only talk to yourself. If you accidentally press `ctrl-x`,
40−it will put you into `:talk`; press `ctrl-x` again to switch back.)
41−
42−### Dojo variables
43−
44−Like the Unix shell, the dojo has command variables. Type
45−
46−```
47−> =a 42
48−```
49−
50−You've set the dojo variable `a` to the value `42`. The dojo
51−puts this binding in the Hoon subject for expressions to use.
52−So you can write:
53−
54−```
55−> a
56−42
57−
58−> [4 a]
59−[4 42]
60−
61−> ? [4 a]
62− {@ud @ud}
63−[4 42]
64−```
65−
66−To unbind `a`, just omit the value:
67−
68−```
69−> =a
70−```
71−
72−You removed `a` from the subject. (We can bind it again later, or
73−bind over it without removing it.)
74−
75−```
76−> [4 a]
77−-find.a
78−```
79−
80−Now trying to use `a` is an error.
81−
82−## Subject-oriented programming
83−
84−What is this *subject* thing, anyway? We put `a` in what?
85−
86−Most programming languages have something called a *scope* or an
87−*environment* or a *context*. This is a data structure that
88−contains the variables and functions an expression can use.
89−
90−In a normal language, the environment is not a first-class value.
91−You cannot save an environment in a variable, compute an
92−expression against the environment in the variable, etc, etc.
93−
94−In Hoon or any "subject-oriented" language, an expression is
95−executed against one normal value, the *subject*. In Hoon, of
96−course, the subject is a noun.
97−
98−## First experiments
99−
100−Up to now, we've only built constants. By definition, a constant
101−doesn't use the subject.
102−
103−It would be nice to start with the subject every dojo expression
104−gets. But that subject is pretty complex. Instead, let's make a
105−simple noun from the kinds of atoms we've already learned about:
106−
107−```
108−> =a [42 [%foo .6.28 ~m45] 0xdead.beef]
109−
110−> ? a
111− {@ud {$foo @rs @dr} @ux}
112−[42 [%foo .3.14 ~m45] 0xdead.beef]
113−
114−> 420:a
115−420
116−```
117−
118−The syntax `expression:expression` uses the product of the second
119−expression as the subject of the first. So we're using `a` as
120−the subject of the expression `420`.
121−
122−Of course, `420` is a constant expression. It doesn't care what
123−the subject is. But:
124−
125−```
126−> (add 2 2):a
127−-find.add
128−```
129−
130−We can't use `a` as the subject of even a simple addition. How
131−could we? There's no `add` function in our `a`. It sometimes
132−takes new Hoon programmers a little while before they realize
133−that there really isn't a scope or environment in Hoon.
134−
135−## Tree geometry
136−
137−So what can we do with this subject? How can we get data out of
138−it? Let's keep working with our little test subject `a`.
139−
140−The most basic way to access the subject is *tree geometry*.
141−Every noun is a binary tree; every noun in the tree has a number
142−which is its address. The root of the tree is `1`; if the
143−address of a cell is `n`, its head is `2n` and its tail is
144−`2n+1`.
145−
146−A picture might help:
147−```
148− 1
149− / \
150− 2 3
151− / \ / \
152− 4 5 6 7
153− / \
154− 14 15
155−```
156−
157−The syntax for a fragment of the subject at a tree address, or
158−*axis*, is just `+axis`. So:
159−
160−```
161−> +3:a
162−[[%foo .3.14 ~m45] 0xdead.beef]
163−
164−> ? +7:a
165− @ux
166−0xdead.beef
167−
168−> ? +13:a
169− {@rs @dr}
170−[.3.14 ~m45]
171−```
172−
173−Of course, the fragment retains the type it had when we built it.
174−
175−## Labeled surfaces
176−
177−We can obviously get anything we want out of the subject by tree
178−geometry. But that's not really how we'd like to program. We'd
179−much rather *label* subtrees with convenient, memorable symbols.
180−
181−For example, suppose our tree looked like:
182−
183−```
184− 1
185− / \
186− x=2 3
187− / \
188− y=6 z=7
189− / \
190− p=14 15
191− / \
192− q=30 r=31
193−```
194−
195−Then instead of writing `+2`, we could write `x`, and so on.
196−
197−Let's replace our test subject `a` with a new noun built around
198−this tree of *labeled surfaces*.
199−
200−```
201−> =a [x=42 y=[p=%foo q=.6.28 r=~m45] z=0xdead.beef]
202−
203−> ? x:a
204− @ud
205−42
206−
207−> ? y:a
208− {p/$foo q/@rs r/@dr}
209−[p=%foo q=.6.28 r=~m45]
210−
211−> ? q.y:a
212− @rs
213−.6.28
214−```
215−
216−Surfaces might remind you of attributes in an object. But again,
217−attributes in an object are a symbol table. There is no symbol
218−table here -- just a tree search.
219−
220−An expression like the label `x` or the axis `+2`, which
221−designates a fragment or feature of the subject, is called a
222−*limb*. A list of limbs connected with `.` is a *wing*.
223−
224−To remind you that you're not in Kansas anymore, the syntax for a
225−wing, like `q.y` above, means means "q inside y." In a classic
226−object-oriented system, of course, this would be written `y.q`,
227−that is, attribute `q` within object `y`. In Hoon, `q.y` means
228−"find limb `y`, then find limb `q` inside that."
229−
230−## Surfaces versus fragments
231−
232−Once again, Hoon has no symbol tables. When we put a surface
233−on a noun, the surface label is part of that noun's type. It's
234−not part of the cell or other structure that contains the noun.
235−This will take a little getting used to:
236−
237−```
238−> ? x:a
239− @ud
240−42
241−
242−> ? +2:a
243− x/@ud
244−x=42
245−
246−? x.+2:a
247− @ud
248−42
249−```
250−
251−When we take fragment 2 of the labeled subject, the *surface
252−comes with it*. `+2` is not `42` but rather `x=42`. We can
253−take the surface off with `x.+2`.
254−
255−## The search algorithm
256−
257−In resolving a label to a fragment axis, we search the subject
258−type in a depth-first traverse.
259−
260−If we find a surface that matches the limb, we succeed. If we
261−find a surface that doesn't match the limb, we fail. If we find
262−a cell, we search first head, then tail.
263−
264−## Skipping
265−
266−What if the same label appears twice in one noun? Let's modify
267−our subject slightly as a test case:
268−
269−```
270−> ? +7:a
271− z/@ux
272−z=0xdead.beef
273−
274−> =a a(+7 x=z:a)
275−
276−> ? a
277− {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}
278−[x=42 y=[p=%foo q=.6.28 r=~m45] x=0xdead.beef]
279−
280−> ? x:a
281− @ud
282−42
283−
284−> ? ^x:a
285− @ux
286−0xdead.beef
287−```
288−
289−We don't want to hide any part of the noun from an expression.
290−So the modified limb `^x` *skips* the first match with a surface
291−`x`, getting us to our `0xdead.beef`. This is a unary notation:
292−`^^x` would skip the first two matches.
293−
294−## Editing
295−
296−Above, we mutated our first noun with the flashy `a(+7 x=z:a)`.
297−
298−Of course we are not really "modifying" a noun. Hoon is a pure
299−language. We are making an edited copy. `a(+7 x=z:a)` means "a
300−copy of `a`, with limb `+7` replaced by the product of `x=z:a`."
301−
302−We can edit multiple (disjoint) wings in one expression:
303−
304−```
305−> ? a(+7 [%hello %world], q.y .3.14)
306− {x/@ud y/{p/$foo q/@rs r/@dr} $hello $world}
307−[x=42 y=[p=%foo q=.3.14 r=~m45] %hello %world]
308−```
309−
310−Notice that nothing stopped us from changing `+7` from
311−`x=0xdead.beef` to `[%hello %world]`. Since the mutated
312−copy is a different noun, it has a different type.
313−
314−(And remember that since `[x y z]` means `[x [y z]]`,
315−`[x y [%hello %world]]` means `[x y %hello %world]`.)
316−
317−## Cores and arms
318−
319−It should be reasonably clear how Hoon's system of fragments and
320−surfaces parallels variables, records or structures in a
321−classical language. But where is Hoon's equivalent of objects:
322−values which bind code to data?
323−
324−The Hoon equivalent of an object is a *core*. As usual in Hoon,
325−the resemblance is inexact. A core has a set of computed
326−attributes, or *arms*. Each arm is an expression whose subject
327−is the core. There is no argument, so an arm is not a method.
328−
329−Physically, a core is always a cell `[battery payload]`, where
330−the *payload* is any noun, and the *battery* is a tree of
331−formulas in Nock (Hoon's functional assembly language) that
332−implements the arms. (A battery is like a C++ vtable, sort of.)
333−
334−## The search algorithm
335−
336−As you'd expect with a computed attribute, there is only one
337−namespace and one search algorithm. We just extend the algorithm
338−described above. And an expression which uses a label can't know
339−whether the subject will resolve it to a surface fragment (a
340−*leg*) or to an arm.
341−
342−If we're searching a core and the label matches one of the core's
343−arms, we compute the arm against the core. If the label is not
344−found, we search into the payload of the core.
345−
346−## Some core examples
347−
348−When you type these examples, make sure you get the number of
349−spaces exactly right. Hoon syntax is not whitespace-sensitive
350−in general, except that "one space" is always a different token
351−from "two or more spaces."
352−
353−```
354−> ? x:a
355− @ud
356−42
357−
358−> ? :per a x
359− @ud
360−42
361−
362−> =b :per a :core ++ foo x ++ bar [q.y foo] --
363−```
364−
365−We're seeing some Hoon regular forms for the first time. `x:a`
366−turns out to be an irregular relative of the regular `:per` form.
367−
368−We'll get more into syntax in a later Urbyte. If some of these
369−examples seem syntactically a little funky, this isn't usually
370−way we'd do them in "real life." We don't normally write cores
371−on a single command line. In a file this would be:
372−
373−```
374− :per a
375− :core
376− ++ foo x
377− ++ bar [q.y foo]
378− --
379−```
380−
381−which is much more readable, at least once you get used to it.
382−Let's look at the core itself:
383−
384−```
385−> b
386−<2.spy {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}>
387−
388−> ? +2:b
389− *
390−[[0 6] [0 58] 9 4 0 1]
391−
392−> ? +3:b
393− {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}
394−[x=42 y=[p=%foo q=.6.28 r=~m45] x=0xdead.beef]
395−```
396−
397−When we print `b`, or any core, we see that typed noun printing
398−can't be an invertible function in Hoon.
399−
400−We actually can read the battery (with `+2:b` above), but it's
401−just Nock code, not typed data. `<2.spy>` tells us the battery
402−has two arms and hashes to the three-letter code `spy`.
403−
404−When printing a full core, we don't even print the payload data,
405−just its type. But our `+3:b` confirms the `[battery payload]`
406−structure of the core. Remember, `+2` is the head and `+3` is
407−the tail.
408−
409−Finally, let's use this thing:
410−
411−```
412−> ? foo:b
413− @ud
414−42
415−
416−> ? bar:b
417− {@rs @ud}
418−[.6.28 42]
419−
420−? x:b
421− @ud
422−42
423−```
424−
425−Seems legit.
426−
427−## The dojo subject
428−
429−Now that we've made a test subject which is a core, we can look
430−directly at the real dojo subject:
431−
432−```
433−> +1
434−[ [ [ a=[x=42 y=[p=%foo q=.6.28 r=~m45] x=0xdead.beef]
435− b=<2.spy {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}>
436− ]
437− now=~2016.7.18..08.05.15..0b5c
438− eny=0vl.hsfrh.tg642.g5o21.1n80b.0h141.0vuan.pm8o4.77ovg.96rk0.n26nn
439− our=~palnul-wolmev-bonfex-danred--tilwen-midlux-bolfus-nocser
440− ]
441− ~
442− <283.xzp 42.ajz 407.xtr 110.xht 1.ztu $151>
443−]
444−```
445−
446−We see a bunch of surfaces: our custom `a` and `b`; standard
447−surfaces for identity, date, and entropy; and a ginormous core
448−stack with *over eight hundred* total arms.
449−
450−To be exact, the syntax `<283.xzp 42.ajz 407.xtr 110.xht 1.ztu
451−$151>` denotes a stack of six cores, each of whose payload is
452−another core, until the innermost payload `%151` (the Hoon
453−version number). This stack is our standard library, from which
454−comes `add` and other fine functions. (We don't know how to
455−write a Hoon function yet, but we're getting way closer.)
456−
457−Let's clean up our subject, just to be hygienic:
458−
459−```
460−> =a
461−> =b
462−
463−> +1
464− now=~2016.7.18..08.10.42..36a0
465− eny=0vf.8j71j.hlqim.k340u.q0ual.v2cd8.cfa65.vkbte.e733g.ehihg.e8aog
466−[ [ our=~palnul-wolmev-bonfex-danred--tilwen-midlux-bolfus-nocser
467− ]
468− ~
469− <283.xzp 42.ajz 407.xtr 110.xht 1.ztu $151>
470−]
471−```
472−
473−Again, remember that `=a` is not Hoon syntax, but `:dojo` syntax.
474−How the dojo assembles this subject remains a mystery. But it's
475−not a particularly interesting mystery.
476−
477−## And we're done
478−
479−And we're done! Type `|exit` to exit:
480−
481−```
482−~palnul_nocser:dojo> |exit
483−%drum-exit
484−$
485−```
486−
487−## Questions and/or exercises
488−
489−As always, these questions are optional and only for fun.
490−
491−What's the best way to construct a core which acts as a function?
492−What do you do to call the function?
493−
494−Why don't any other languages use subject-oriented programming?
495−Which languages are most similar to it?