on master help sign in
typo
5fcbd65Galen Wolfe-Pauly
docs/byte/2.md+13−14
@@ -1,10 +1,9 @@
1---
1---
2navhome: /docs
2navhome: /docs
3sort: 3
3sort: 3
4−next: false
5title: Subject-oriented programming
4title: Subject-oriented programming
6---
5---
7−
6+
8# Urbyte 2: subject-oriented programming
7# Urbyte 2: subject-oriented programming
9
8
10Thanks for reading Urbytes 0 and 1! In Urbyte 2, we'll take
9Thanks for reading Urbytes 0 and 1! In Urbyte 2, we'll take
@@ -37,7 +36,7 @@ are expressions.
37
36
38(The dojo is not the only command-line app on your Urbit. By
37(The dojo is not the only command-line app on your Urbit. By
39default there is one other, `:talk`. Since you're on a fakezod,
38default there is one other, `:talk`. Since you're on a fakezod,
40−you can only talk to yourself. If you accidentally press `^X`,
39+you can only talk to yourself. If you accidentally press `^X`,
41it will put you into `:talk`; press `^X` again to switch back.)
40it will put you into `:talk`; press `^X` again to switch back.)
42
41
43### Dojo variables
42### Dojo variables
@@ -96,7 +95,7 @@ In Hoon or any "subject-oriented" language, an expression is
96executed against one normal value, the *subject*. In Hoon, of
95executed against one normal value, the *subject*. In Hoon, of
97course, the subject is a noun.
96course, the subject is a noun.
98
97
99−## First experiments
98+## First experiments
100
99
101Up to now, we've only built constants. By definition, a constant
100Up to now, we've only built constants. By definition, a constant
102doesn't use the subject.
101doesn't use the subject.
@@ -142,20 +141,20 @@ The most basic way to access the subject is *tree geometry*.
142Every noun is a binary tree; every noun in the tree has a number
141Every noun is a binary tree; every noun in the tree has a number
143which is its address. The root of the tree is `1`; if the
142which is its address. The root of the tree is `1`; if the
144address of a cell is `n`, its head is `2n` and its tail is
143address of a cell is `n`, its head is `2n` and its tail is
145−`2n+1`.
144+`2n+1`.
146
145
147A picture might help::
146A picture might help::
148```
147```
149 1
148 1
150 / \
149 / \
151− 2 3
150+ 2 3
152 / \ / \
151 / \ / \
153 4 5 6 7
152 4 5 6 7
154 / \
153 / \
155 14 15
154 14 15
156```
155```
157
156
158−The syntax for a fragment of the subject at a tree address, or
157+The syntax for a fragment of the subject at a tree address, or
159*axis*, is just `+axis`. So:
158*axis*, is just `+axis`. So:
160
159
161```
160```
@@ -184,7 +183,7 @@ For example, suppose our tree looked like:
184```
183```
185 1
184 1
186 / \
185 / \
187− x=2 3
186+ x=2 3
188 / \
187 / \
189 y=6 z=7
188 y=6 z=7
190 / \
189 / \
@@ -298,7 +297,7 @@ Above, we mutated our first noun with the flashy `a(+7 x=z:a)`.
298
297
299Of course we are not really "modifying" a noun. Hoon is a pure
298Of course we are not really "modifying" a noun. Hoon is a pure
300language. We are making an edited copy. `a(+7 x=z:a)` means "a
299language. We are making an edited copy. `a(+7 x=z:a)` means "a
301−copy of `a`, with limb `+7` replaced by the product of `x=z:a`."
300+copy of `a`, with limb `+7` replaced by the product of `x=z:a`."
302
301
303We can edit multiple (disjoint) wings in one expression:
302We can edit multiple (disjoint) wings in one expression:
304
303
@@ -349,7 +348,7 @@ found, we search into the payload of the core.
349When you type these examples, make sure you get the number of
348When you type these examples, make sure you get the number of
350spaces exactly right. Hoon syntax is not whitespace-sensitive
349spaces exactly right. Hoon syntax is not whitespace-sensitive
351in general, except that "one space" is always a different token
350in general, except that "one space" is always a different token
352−from "two or more spaces."
351+from "two or more spaces."
353
352
354```
353```
355> ? x:a
354> ? x:a
@@ -384,7 +383,7 @@ Let's look at the core itself:
384
383
385```
384```
386> b
385> b
387−<2.spy {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}>
386+<2.spy {x/@ud y/{p/$foo q/@rs r/@dr} x/@ux}>
388
387
389> ? +2:b
388> ? +2:b
390 *
389 *
@@ -396,11 +395,11 @@ Let's look at the core itself:
396```
395```
397
396
398When we print `b`, or any core, we see that typed noun printing
397When we print `b`, or any core, we see that typed noun printing
399−can't be an invertible function in Hoon.
398+can't be an invertible function in Hoon.
400
399
401We actually can read the battery (with `+2:b` above), but it's
400We 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
401+just Nock code, not typed data. `<2.spy>` tells us the battery
403−has two arms and hashes to the three-letter code `spy`.
402+has two arms and hashes to the three-letter code `spy`.
404
403
405When printing a full core, we don't even print the payload data,
404When printing a full core, we don't even print the payload data,
406just its type. But our `+3:b` confirms the `[battery payload]`
405just its type. But our `+3:b` confirms the `[battery payload]`