on master help sign in
Various fixes and improvements.
commitd6be9a1d833b49f3544dce4c8006c52c6165f757 authorC. Guy Yarvin <cgyarvin@gmail.com> dateTue 19 Jul 2016, 09:53 (10 years ago) parent572a7e3
3 files changed+115−63
docs/byte/0.md+4−2 docs/byte/1.md+45−26 docs/byte/2.md+66−35
docs/byte/0.md+4−2
@@ -40,8 +40,10 @@ In the Urbyte exercises you'll be running what we call a "fake
4040`~zod`." A string starting with `~`, like `~zod`, is what Urbit
4141calls a *ship*.
4242
43−A ship is one number which means four things: a network address, a
44−cryptographic identity, a memorable name, and a single virtual computer.
43+A *ship* is one number which means four things: a network address,
44+a cryptographic identity, a memorable name, and a single virtual
45+computer.
46+
4547We write this number in a base-256 format, where each digit is a
4648syllable. Imagine if your phone number was a pronounceable
4749string which sounded like a name in a foreign language.
docs/byte/1.md+45−26
@@ -22,22 +22,28 @@ http: live (insecure, loopback) on 12321
2222~zod:dojo>
2323```
2424
25−## The atom question
25+## What's in an atom?
2626
2727It seems limiting to have only one kind of atom, the unsigned
2828decimal. How are signed integers represented? Symbols?
2929Floating-point values? Dates? IP addresses? Even just hex?
3030
31−The Lisp S-expression, with cons cells and atoms, is very similar
32−to Hoon's nouns. But languages in the Lisp family mark each atom
33−with a dynamic tag that defines the atom's meaning. These tags
34−are effectively dynamic types.
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.
3535
3636Hoon also tracks the meaning of atoms. But Hoon is statically
3737typed, so an atom description is obviously a type. An atomic type
3838in Hoon is called an *aura*. The aura syntax is just an ASCII
3939string starting with `@`, like `@ud` for unsigned decimal.
4040
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+
4147## Examples
4248
4349With the dojo command `? expression`, you tell the dojo to print
@@ -105,7 +111,7 @@ can't enforce any constraints the aura puts on the atom's value.
105111```
106112
107113`--7` means "positive 7." `+7` might have been better, but `+`
108−is not URL-safe, and every regular atom syntax fits in a URL.
114+is not URL-safe.
109115
110116Hoon needs `--` to distinguish positive signed numbers because
111117Hoon's type system doesn't feed back into its parser. The
@@ -130,6 +136,14 @@ slightly clunkier syntax in exchange for much simpler semantics.
130136 @ux
1311370x7469.6272.9cc3
132138
139+> ? ~~Ürbit
140+ @t
141+'Ürbit'
142+
143+? >~.urbit
144+ @ta
145+~.urbit
146+
133147> ? `@ux`'foo'
134148 @ux
1351490x6f.6f66
@@ -140,6 +154,11 @@ Hoon doesn't actually have the power to check statically that
140154your UTF-8 is valid. Auras don't tell you what an atom is, just
141155what you think it is.
142156
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+
143162### Dates, floats, IP addresses...
144163
145164```
@@ -174,35 +193,35 @@ what you think it is.
174193`@da` is a 128-bit absolute date (64 bits for fractions of a
175194second, 64 bits for seconds); `@dr` is a relative date; `@rs` is
176195a single-precision IEEE real; `@if` is an IPv4 address. This is
177−not all Hoon's aura syntax, but it's a good range of examples.
196+not all Hoon's aura syntax, just a good range of examples.
178197
179198`(add ~h6 now)` is a good example of the use and limits of
180199the aura system. Unlike the signed-integer sum, offsetting a
181200date can use plain atomic addition. But the product of `add` is
182−a flavorless atom with no aura, so we have to cast it back to an
183−absolute date `@da`.
201+a flavorless atom with no aura, `@`. So we have to cast it back
202+to an absolute date `@da`.
184203
185204## Auras explained
186205
187206Does an aura represent the units of the atom, its syntax, its
188207semantics, its constraints?
189208
190−It can mean any or all of these. Programmers can even use their
191−own aura strings which nothing in Hoon recognizes. The set of
192−syntaxes that Hoon knows how to parse and print is fixed. But
193−there are plenty of reasons to introduce user-defined auras.
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.
194213
195−If your program uses both fortnights and furlongs, the aura
196−system will not parse a fortnight syntax or print furlongs in the
197−dojo. It will keep you from accidentally confusing the two,
198−which is probably most of what you want.
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.
199218
200−Hoon does interpret the string in one way: auras specialize to
201−the right. For example, `@u` is any unsigned integer; `@ux` is
202−an unsigned integer that likes to be printed as hex.
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.
203222
204223Hoon's typechecker lets you go up or down the specialization
205−ladder, but complains if you try to go across. For example,
224+ladder. It complains if you try to move across. For example,
206225`@u` can silently convert into `@ux` or `@ux` into `@u`, but
207226turning `@ud` into `@ux`, `@ux` into `@da`, etc, requires an
208227explicit cast.
@@ -288,7 +307,7 @@ infix hyphens ("kebab-case").
288307Loobeans are not true and false, but yes (`.y` or `&`) and no
289308(`.n` or `|`). This is because *yes is zero and no is one*.
290309This makes sense at a certain mathematical level, though it
291−was probably a mistake.
310+was probably a mistake from a practical perspective.
292311
293312`~` is Hoon's nil: constant `0`, aura `@n`.
294313
@@ -326,15 +345,15 @@ $
326345
327346As always, these questions are optional and only for fun.
328347
329−We didn't include anywhere near all auras or syntaxes in this
330−lesson. It's just a set of examples.
348+We didn't include anywhere near all Hoon's auras or syntaxes in
349+this lesson. It's just a set of examples.
331350
332351Try using the dojo's magic error erasure to stumble around the
333352rest of Hoon's atom syntax. Any string that can't be extended
334353into a valid expression will be trimmed back, with a beep, until
335354it can. Return will beep if the expression is not complete.
336−This feedback is harmless and does not use an electric shock,
337−but it enables stochastic reinforcement learning of Hoon syntax.
355+This feedback is harmless and does not use an electric shock.
356+It enables stochastic reinforcement learning of Hoon syntax.
338357
339358If `~h6` is six hours, how do you write forty-five minutes? Two
340359days, six hours and forty-five minutes?
docs/byte/2.md+66−35
@@ -176,7 +176,7 @@ Of course, the fragment retains the type it had when we built it.
176176## Labeled surfaces
177177
178178We can obviously get anything we want out of the subject by tree
179−geometry. But it's not really how we'd like to program. We'd
179+geometry. But that's not really how we'd like to program. We'd
180180much rather *label* subtrees with convenient, memorable symbols.
181181
182182For example, suppose our tree looked like:
@@ -220,7 +220,7 @@ table here -- just a tree search.
220220
221221An expression like the label `x` or the axis `+2`, which
222222designates a fragment or feature of the subject, is called a
223−*limb*. Limbs can be connected with a `.`, making a *wing*.
223+*limb*. A list of limbs connected with `.`, is a *wing*.
224224
225225To remind you that you're not in Kansas anymore, the syntax for a
226226wing, like `q.y` above, means means "q inside y." In a classic
@@ -233,7 +233,7 @@ that is, attribute `q` within object `y`. In Hoon, `q.y` means
233233Once again, Hoon has no symbol tables. When we put a surface
234234on a noun, the surface label is part of that noun's type. It's
235235not part of the cell or other structure that contains the noun.
236−For example:
236+This will take a little getting used to:
237237
238238```
239239> ? x:a
@@ -249,8 +249,8 @@ x=42
24924942
250250```
251251
252−When we take fragment 2 of the labeled subject the *surface
253−comes with it *. `+2` is not `42` but rather `x=42`. We can
252+When we take fragment 2 of the labeled subject, the *surface
253+comes with it*. `+2` is not `42` but rather `x=42`. We can
254254take the surface off with `x.+2`.
255255
256256## The search algorithm
@@ -323,18 +323,22 @@ classical language. But where is Hoon's equivalent of objects:
323323values which bind code to data?
324324
325325The Hoon equivalent of an object is a *core*. As usual in Hoon,
326−the resemblance isn't exact. A core has a set of computed
326+the resemblance is inexact. A core has a set of computed
327327attributes, or *arms*. Each arm is an expression whose subject
328328is the core. There is no argument, so an arm is not a method.
329329
330330Physically, a core is always a cell `[battery payload]`, where
331331the *payload* is any noun, and the *battery* is a tree of
332332formulas in Nock (Hoon's functional assembly language) that
333−implements the arms.
333+implements the arms. (A battery is like a C++ vtable, sort of.)
334334
335−As you'd expect with a computed attribute, an expression which
336−uses a label can't know whether the subject will resolve it to a
337−surface fragment (a *leg*) or to an arm.
335+## The search algorithm
336+
337+As you'd expect with a computed attribute, there is only one
338+namespace and one search algorithm. We just extend the algorithm
339+described above. And an expression which uses a label can't know
340+whether the subject will resolve it to a surface fragment (a
341+*leg*) or to an arm.
338342
339343If we're searching a core and the label matches one of the core's
340344arms, we compute the arm against the core. If the label is not
@@ -357,10 +361,55 @@ from "two or more spaces."
35736142
358362
359363> =b :per a :core ++ foo x ++ bar [q.y foo] --
364+```
365+
366+We're seeing some Hoon regular forms for the first time. `x:a`
367+turns out to be an irregular relative of the regular `:per` form.
368+
369+We'll get more into syntax in a later Urbyte. If some of these
370+examples seem syntactically a little funky, this isn't usually
371+way we'd do them in "real life." We don't normally write cores
372+on a single command line. In a file this would be:
373+
374+```
375+ :per a
376+ :core
377+ ++ foo x
378+ ++ bar [q.y foo]
379+ --
380+```
381+
382+which is much more readable, at least once you get used to it.
383+Let's look at the core itself:
360384
385+```
361386> b
362387<2.spy {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}>
363388
389+> ? +2:b
390+ *
391+[[0 6] [0 58] 9 4 0 1]
392+
393+> ? +3:b
394+ {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}
395+[x=42 y=[p=%foo q=.6.28 r=~m45] x=0xdead.beef]
396+```
397+
398+When we print `b`, or any core, we see that typed noun printing
399+can't be an invertible function in Hoon.
400+
401+We actually can read the battery (with `+2:b` above), but it's
402+just Nock code, not typed data. `<2.spy>` tells us the battery
403+has two arms and hashes to the three-letter code `spy`.
404+
405+When printing a full core, we don't even print the payload data,
406+just its type. But our `+3:b` confirms the `[battery payload]`
407+structure of the core. Remember, `+2` is the head and `+3` is
408+the tail.
409+
410+Finally, let's use this thing:
411+
412+```
364413> ? foo:b
365414 @ud
36641542
@@ -372,27 +421,9 @@ from "two or more spaces."
372421? x:b
373422 @ud
37442342
375−
376−> ? +2:b
377− *
378−[[0 6] [0 58] 9 4 0 1]
379424```
380425
381−We're seeing some Hoon regular forms for the first time. `x:a`
382−turns out to be an irregular relative of the regular `:per` form.
383−
384−(We'll get more into syntax in a later Urbyte. If some of these
385−examples seem syntactically a little funky, this isn't usually
386−way we'd do them in "real life." We don't normally write cores
387−on one line in the dojo, for instance.)
388−
389−And when we print `b`, or any core, we see that typed noun
390−printing can't be an invertible function in Hoon.
391−
392−We actually can read the battery (with `+2:b` above), but it's
393−just Nock code, not typed data. We don't even print the payload
394−data, though we print the payload type. The `<2.spy>` just shows
395−a core with two arms, for which `spy` is a hash code.
426+Seems legit.
396427
397428## The dojo subject
398429
@@ -415,14 +446,14 @@ directly at the real dojo subject:
415446
416447We see a bunch of surfaces: our custom `a` and `b`; standard
417448surfaces for identity, date, and entropy; and a ginormous core
418−stack with almost a thousand total arms.
449+stack with *over eight hundred* total arms.
419450
420451To be exact, the syntax `<283.xzp 42.ajz 407.xtr 110.xht 1.ztu
421−$151>` denotes a system of six cores, each of whose payload is
452+$151>` denotes a stack of six cores, each of whose payload is
422453another core, until the innermost payload `%151` (the Hoon
423−version). This stack is our standard library, from which comes
424−`add` and other fine functions. (We don't know how to define a
425−Hoon function yet, but we're getting close.)
454+version number). This stack is our standard library, from which
455+comes `add` and other fine functions. (We don't know how to
456+write a Hoon function yet, but we're getting way closer.)
426457
427458Let's clean up our subject, just to be hygienic:
428459
@@ -458,7 +489,7 @@ $
458489As always, these questions are optional and only for fun.
459490
460491What's the best way to construct a core which acts as a function?
461−How do you call the function?
492+What do you do to call the function?
462493
463494Why don't any other languages use subject-oriented programming?
464495Which languages are most similar to it?