on master help sign in
rewrote Hoon 1.4 for clarity, various other minor ch 1 revisions
7b25e0bjoshuareagan
docs/tutorials/hoon-ch1/hoon-ch1-1.udon−2
@@ -98,8 +98,6 @@ http: live (insecure, loopback) on 12321
98~palnul_nocser:dojo>
98~palnul_nocser:dojo>
99```
99```
100
100
101−We should note that your comet's state is [ACID](https://en.wikipedia.org/wiki/ACID). You can stop your comet politely with `ctrl-d`, abruptly with `ctrl-z`, even violently with `kill -9`. None of these should cause the comet to lose data. If you do manage to corrupt your comet, it's a bug -- please let us know.
102−
103## Another Noun
101## Another Noun
104
102
105You've already used a standard library function to produce one value, in the dojo. Now that your comet is running again, let's try another. Enter the number `17`.
103You've already used a standard library function to produce one value, in the dojo. Now that your comet is running again, let's try another. Enter the number `17`.
docs/tutorials/hoon-ch1/hoon-ch1-2.udon+19−25
@@ -8,7 +8,7 @@
8
8
9# 1.2 Nouns
9# 1.2 Nouns
10
10
11−In Urbit every piece of data (that is, every 'datum') is a noun. In order to understand Hoon one must first understand nouns.
11+In Urbit every piece of data is a noun. In order to understand Hoon one must first understand nouns.
12
12
13## Noun Definition
13## Noun Definition
14
14
@@ -33,13 +33,13 @@ All of the above are nouns.
33
33
34You may or may not have noticed that the definition of 'noun' is [recursive](https://en.wikipedia.org/wiki/Recursion). Recursion is an important concept for functional programming, so it's worth taking a moment to understand it better.
34You may or may not have noticed that the definition of 'noun' is [recursive](https://en.wikipedia.org/wiki/Recursion). Recursion is an important concept for functional programming, so it's worth taking a moment to understand it better.
35
35
36−A recursive definition has three clauses: a base clause, a generating clause, and a closure clause. Let's say you want to use recursion to define some X. The *base clause* of the recursive definition defines one or more objects as trivial instances of X. The *generating clause* defines other objects as also being X by their relationship to previously established instances of X. The *closure clause* asserts that nothing else is an instance of X than what has been given in the first two clauses. Often the closure clause is not explicitly stated.
36+A recursive definition has three clauses: a base clause, a generating clause, and a closure clause. Let's say you want to use recursion to define some X. The definition should allow one to determine whether any given object is a member of X. The *base clause* of the recursive definition defines one or more objects as trivial members of X. The *generating clause* defines other objects as also being X by their relationship to previously established members of X. The *closure clause* asserts that nothing else is a member of X than what has been given in the first two clauses. Often the closure clause is not explicitly stated.
37
37
38−For example, let's say you want to define the phrase 'ancestor of George Washington'. The base clause is simple: the parents of George Washington are trivial ancestors of George Washington. The generating clause is: given that some x is an ancestor of George Washington, the parents of x are also ancestors of George Washington. The closure clause is: no one else is an ancestor of George Washington. That's it!
38+For example, let's say you want to define the phrase 'ancestor of George Washington'. Which 'objects' are members of that set? The base clause is simple: the parents of George Washington are trivial ancestors of George Washington. The generating clause is: given that some x is an ancestor of George Washington, the parents of x are also ancestors of George Washington. The closure clause is: nothing else is an ancestor of George Washington. That's it!
39
39
40−The base clause of the definition of a 'noun' is: all atoms are nouns (where an 'atom' is an unsigned integer). The generating clause is: if x and y are nouns, then the cell `[x y]` is also a noun. (A 'cell' is an ordered pair of nouns.). The closure clause was given implicitly in the following claim: "A *noun* is either an atom or a cell." Nothing else is a noun.
40+Let's restate the definition of *noun* in these terms. The base clause of the definition of a 'noun' is: all atoms are nouns (where an 'atom' is an unsigned integer). The generating clause is: if x and y are nouns, then the cell `[x y]` is also a noun. (A 'cell' is an ordered pair of nouns.). The closure clause is: nothing else is a noun.
41
41
42−We belabor this point about recursion only because it's an important concept for having a firm grasp of functional programming. We'll talk more about recursion at various points in the tutorial series.
42+We belabor this point about recursion only because it's an important concept for having a firm grasp of functional programming. We'll talk more about recursion at various points in this series.
43
43
44### Nouns as Binary Trees
44### Nouns as Binary Trees
45
45
@@ -54,7 +54,7 @@ A [binary tree](https://en.wikipedia.org/wiki/Binary_tree) has a single base nod
54 17 45
54 17 45
55```
55```
56
56
57−Each number is an atom; each dot is a cell. Let's look at another example, this time of `[[7 13] [87 65]]` with the cell nodes shown explicitly:
57+Each number is an atom; each dot is a cell. Let's look at another example, this time of `[[7 13] [87 65]]`, with the cell nodes shown explicitly:
58
58
59```
59```
60 [[7 13] [87 65]]
60 [[7 13] [87 65]]
@@ -117,13 +117,13 @@ Why? Long numbers are difficult to read. We know this, so we group digits in t
117
117
118English notation for decimals is more common than German notation. Unfortunately, dots are URL-safe and commas aren't. For reasons to be discussed in a later lesson, it's nice to have a regular syntax for atoms that's URL-safe.
118English notation for decimals is more common than German notation. Unfortunately, dots are URL-safe and commas aren't. For reasons to be discussed in a later lesson, it's nice to have a regular syntax for atoms that's URL-safe.
119
119
120−As for why the dojo deleted your zero: it parses the command line as you type, and rejects any characters after the parser stops. This prevents you from entering expressions that aren't well-formed.
120+As for why the dojo deleted your zero: it parses the command line as you type, and rejects any characters after the parser stops. This prevents you from entering commands or expressions that aren't well-formed.
121
121
122### Atom Auras
122### Atom Auras
123
123
124−Atoms are nothing more than unsigned integers, but it's often useful to interpret an atom as being a different kind of data. This is done with an *aura* -- the aura of an atom is type meta-data used by Hoon to determine how interpret that atom.
124+Atoms are nothing more than unsigned integers, but it's often useful to interpret an atom as being a different kind of data. This is done with an *aura*. The aura of an atom is type meta-data used by Hoon to determine how interpret that atom. It answers the question: What type of information is this atom?
125
125
126−We won't fully explain auras and their various uses yet. Auras will be covered more comprehensively in a later lesson. For now let's just look at the various kinds of [literal syntax](https://en.wikipedia.org/wiki/Literal_(computer_programming%29) associated with atom auras.
126+We won't fully explain auras and their various uses yet. Auras will be covered more comprehensively in a later lesson. For now let's just look at the various kinds of [literal syntax](https://en.wikipedia.org/wiki/Literal_(computer_programming%29) associated with a few atom auras.
127
127
128In computer science, a 'literal' is an expression that represents and evaluates to a fixed value. The default syntax of an atom literal is the German-style decimal notation, as seen above. Let's look at some other atom literal syntaxes: unsigned binary, unsigned hexadecimal, signed decimal, signed binary and hexadecimal.
128In computer science, a 'literal' is an expression that represents and evaluates to a fixed value. The default syntax of an atom literal is the German-style decimal notation, as seen above. Let's look at some other atom literal syntaxes: unsigned binary, unsigned hexadecimal, signed decimal, signed binary and hexadecimal.
129
129
@@ -153,7 +153,7 @@ In computer science, a 'literal' is an expression that represents and evaluates
153-0x9d
153-0x9d
154```
154```
155
155
156−All of the above are atoms. The underlying noun of each is just an unsigned integer, but each is written in a special syntax indicating to Hoon that the atom is to be represented in a different way. To see their values in the default atom notation, you can tell Hoon to throw away the aura information. Do this by preceding each expression above with `` `@` ``.
156+All of the above are atoms. The underlying noun of each is just an unsigned integer, but each is written in a special syntax indicating to Hoon that the atom is to be represented in a different way. To see their values in the default atom notation, you can tell Hoon to throw away the aura information. Do this by preceding each expression above with `\`@\``.
157
157
158```
158```
159> `@`0b1001
159> `@`0b1001
@@ -181,28 +181,22 @@ All of the above are atoms. The underlying noun of each is just an unsigned int
181313
181313
182```
182```
183
183
184−The `` `@` `` syntax is used to 'cast' a value to a raw atom, i.e., an atom without an aura. Don't worry about exactly what `` `@` `` means just yet. Casts will be explained in more detail in a later lesson. For now all you need to know is that a cast doesn't change the underlying value of the noun; it's used here only to change how the value is printed in the dojo output.
184+The `\`@\`` syntax is used to 'cast' a value to a raw atom, i.e., an atom without an aura. Don't worry about exactly what `\`@\`` means just yet. Casts will be explained in more detail in a later lesson. For now all you need to know is that a cast doesn't change the underlying value of the noun; it's used here only to change how the value is printed in the dojo output.
185
185
186#### Identities, Cords, and Terms
186#### Identities, Cords, and Terms
187
187
188−Urbit identities such as `~zod`, `~taglux-nidsep`, and `~sorreg-namtyv` are also atoms with their own distinctive syntax:
188+Urbit identities such as `~zod` and `~sorreg-namtyv` are also atoms with their own distinctive syntax:
189
189
190```
190```
191> ~zod
191> ~zod
192~zod
192~zod
193
193
194−> ~taglux-nidsep
195−~taglux-nidsep
196−
197> ~sorreg-namtyv
194> ~sorreg-namtyv
198~sorreg-namtyv
195~sorreg-namtyv
199
196
200> `@`~zod
197> `@`~zod
2010
1980
202
199
203−> `@`~taglux-nidsep
204−6.095.360
205−
206> `@`~sorreg-namtyv
200> `@`~sorreg-namtyv
2075.702.400
2015.702.400
208```
202```
@@ -278,7 +272,7 @@ Aura Meaning Example of Literal Syntax
278
272
279#### Casting to Other Auras
273#### Casting to Other Auras
280
274
281−You can force Hoon to interpret an atom differently by using the aura symbols in the chart above; e.g., `` `@ux` `` for unsigned hexadecimal, `` `@ub` `` for unsigned binary, etc.:
275+You can force Hoon to interpret an atom differently by using the aura symbols in the chart above; e.g., `\`@ux\`` for unsigned hexadecimal, `\`@ub\`` for unsigned binary, etc.:
282
276
283```
277```
284> `@ux`157
278> `@ux`157
@@ -332,7 +326,7 @@ I said there isn't _much_ mystery about cells, but there is a little. So far wh
332
326
333In the first example, the inner pair of square brackets is dropped. Why did this happen? Why is `[6 62 620]` accepted as a cell despite apparently having more than two atoms in it?
327In the first example, the inner pair of square brackets is dropped. Why did this happen? Why is `[6 62 620]` accepted as a cell despite apparently having more than two atoms in it?
334
328
335−In fact, `[6 [62 620]]` and `[6 62 620]` are considered equivalent in Hoon. A cell _must_ be a pair, which means there are always exactly two nouns in it. Whenever cell brackets are left out of the interior of a cell, so that visually there seem to be more than two child nouns, it is implicitly understood that the right-most nouns constitute a cell. That is, the tail of the whole cell is assumed to be a cell of the right-most nouns.
329+In fact, `[6 [62 620]]` and `[6 62 620]` are considered equivalent in Hoon. A cell _must_ be a pair, which means there are always exactly two nouns in it. Whenever cell brackets are omitted so that visually there appears to be more than two child nouns, it is implicitly understood that the right-most nouns constitute a cell. That is, the tail of the whole cell is assumed to be a cell of the right-most nouns.
336
330
337This is why `[6 [62 620]]` and `[6 62 620]` are equivalent. `[6 [62 620]]` and `[[6 62] 620]`, on the other hand, are not equivalent. If you look at them as binary trees you can see the difference:
331This is why `[6 [62 620]]` and `[6 62 620]` are equivalent. `[6 [62 620]]` and `[[6 62] 620]`, on the other hand, are not equivalent. If you look at them as binary trees you can see the difference:
338
332
@@ -354,7 +348,7 @@ When the dojo pretty-prints a cell it always removes superfluous cell brackets:
354
348
355However, you should always remember that though cells can be presented as lists of more than two nouns, they're always just pairs.
349However, you should always remember that though cells can be presented as lists of more than two nouns, they're always just pairs.
356
350
357−### Exercise 1.1.1
351+### Exercise 1.2.1
358
352
359Without using the dojo, assess whether each of the following pairs of nouns is equivalent. (Answers are at the bottom of the page.)
353Without using the dojo, assess whether each of the following pairs of nouns is equivalent. (Answers are at the bottom of the page.)
360
354
@@ -372,7 +366,7 @@ Nouns have a regular structure that can be exploited to give a unique *address*
372
366
373What if you want to refer to a noun fragment, and not the whole thing? For example, what if you want to refer to the `[6 2]` part of `[[1 3] [6 2]]`? One way is to use the unique address of that noun fragment.
367What if you want to refer to a noun fragment, and not the whole thing? For example, what if you want to refer to the `[6 2]` part of `[[1 3] [6 2]]`? One way is to use the unique address of that noun fragment.
374
368
375−To define noun addresses we'll need to use recursion. The base case is trivial: address `1` of a noun is the entire noun. The generating case: if the noun at address `n` is a cell, then its head is at address `2n` and its tail is at address `2n + 1`. For example, if address `5` of some noun is a cell, then its head is at address `10` and its tail address `11`.
369+To define noun addresses we'll use recursion. The base case is trivial: address `1` of a noun is the entire noun. The generating case: if the noun at address `n` is a cell, then its head is at address `2n` and its tail is at address `2n + 1`. For example, if address `5` of some noun is a cell, then its head is at address `10` and its tail address `11`.
376
370
377Address 1 of the noun `[[1 3] [6 2]]` is the whole noun: `[[1 3] [6 2]]`. The head of the noun at address `1`, `[1 3]`, is at address `2 x 1`, i.e., `2`. The tail of the noun at address `1`, `[6 2]`, is at address `(2 x 1) + 1`, i.e., `3`.
371Address 1 of the noun `[[1 3] [6 2]]` is the whole noun: `[[1 3] [6 2]]`. The head of the noun at address `1`, `[1 3]`, is at address `2 x 1`, i.e., `2`. The tail of the noun at address `1`, `[6 2]`, is at address `(2 x 1) + 1`, i.e., `3`.
378
372
@@ -413,7 +407,7 @@ What happens if you ask for a fragment that doesn't exist?
413
407
414```
408```
415> +4:[22 [33 44]]
409> +4:[22 [33 44]]
416−ford: build failed *stack trace*
410+ford: %ride failed to execute:
417```
411```
418
412
419Let's do a few more examples:
413Let's do a few more examples:
@@ -441,7 +435,7 @@ As before, the root of the binary tree (i.e., the whole noun) is at address `1`.
441
435
442Address `1110` indicates "the head of the tail of the tail of the noun".
436Address `1110` indicates "the head of the tail of the tail of the noun".
443
437
444−### Exercise 1.1.2
438+### Exercise 1.2.2
445
439
446Without using the dojo, evaluate the following expressions. (Answers are at the bottom of the page.)
440Without using the dojo, evaluate the following expressions. (Answers are at the bottom of the page.)
447
441
@@ -453,7 +447,7 @@ Without using the dojo, evaluate the following expressions. (Answers are at the
4535. +10:[[[2 4 5] [3 6]] 11]
4475. +10:[[[2 4 5] [3 6]] 11]
454```
448```
455
449
456−### Exercise 1.1.3
450+### Exercise 1.2.3
457
451
458Without using the dojo, for each fragment below provide the address relative to the noun `[51 52 53 54 55]`. (Answers are at the bottom of the page.)
452Without using the dojo, for each fragment below provide the address relative to the noun `[51 52 53 54 55]`. (Answers are at the bottom of the page.)
459
453
docs/tutorials/hoon-ch1/hoon-ch1-3.udon+33−33
@@ -36,7 +36,7 @@ In the examples above, the expression on the right-hand, `[[11 22] 33]`, evaluat
36[[11 22] 33]
36[[11 22] 33]
37```
37```
38
38
39−...so the subject for the left-hand expression is simply `[[11 22] 33]`. The `+` operator is used to produce some fragment of the subject at a given address. E.g., `+2`, returns whatever is at address `2` of the subject. Hence, we may read `+2:[[11 22] 33]` as "address `2` of the subject produced by `[[11 22] 33]`".
39+...so the subject for the left-hand expression, `+1`, is simply `[[11 22] 33]`. The `+` operator is used to produce some fragment of the subject at a given address. E.g., `+2`, returns whatever is at address `2` of the subject. Hence, we may read `+2:[[11 22] 33]` as "address `2` of the subject produced by `[[11 22] 33]`".
40
40
41Let's create a subject with some computations:
41Let's create a subject with some computations:
42
42
@@ -82,7 +82,7 @@ Sometimes a programmer simply wants to produce a value from the subject. In oth
82
82
83### Address-based Limb Expressions
83### Address-based Limb Expressions
84
84
85−A limb expression is an expression of Hoon that resolves to a limb of the subject. An address-based limb expression evaluates to a limb of the subject based on its address. (You learned about the noun address system in the last lesson.)
85+A limb expression is an expression of Hoon that resolves to a limb of the subject. An address-based limb expression evaluates to a limb of the subject based on its noun address. (You learned about the noun address system in the last lesson.)
86
86
87In the following you'll learn the various limb expressions available in Hoon, as well as how they work when they resolve to legs. First we'll explain the limb expressions that return a leg according to subject address.
87In the following you'll learn the various limb expressions available in Hoon, as well as how they work when they resolve to legs. First we'll explain the limb expressions that return a leg according to subject address.
88
88
@@ -134,7 +134,7 @@ To think of it another way, `-` is for the left and `+` is for the right. You c
134
134
135```
135```
136> +:12
136> +:12
137−ford: build failed [crash message]
137+ford: %ride failed to execute:
138```
138```
139
139
140What if you want the tail of the tail of the subject? You might expect that you can double up on `+` for this: `++`. Not so. Instead, combine `+` with `>`: `+>`. `>` means the same thing as `+`, but is used with `+` to make for easier reading.
140What if you want the tail of the tail of the subject? You might expect that you can double up on `+` for this: `++`. Not so. Instead, combine `+` with `>`: `+>`. `>` means the same thing as `+`, but is used with `+` to make for easier reading.
@@ -252,7 +252,7 @@ As with `&n`, we can characterize `|n` recursively. In the base case, `|1` is `
252
252
253Working with specific addresses of the subject can be cumbersome even when the subject is small. When the subject is a really large noun -- as is often the case -- it's downright impractical. Thankfully there's a more convenient method for resolving to a limb of the subject: using names.
253Working with specific addresses of the subject can be cumbersome even when the subject is small. When the subject is a really large noun -- as is often the case -- it's downright impractical. Thankfully there's a more convenient method for resolving to a limb of the subject: using names.
254
254
255−A name can resolve to either an arm or a leg of the subject. Recall that arms are for computations and legs are for data. When a name resolves to an arm, the relevant computation is run and the product of the computation is produced. When a limb name resolves to a leg, the value of that leg is produced. We aren't yet ready to talk about arm resolution; for now let's focus on leg names.
255+A name can resolve either an arm or a leg of the subject. Recall that arms are for computations and legs are for data. When a name resolves to an arm, the relevant computation is run and the product of the computation is produced. When a limb name resolves to a leg, the value of that leg is produced. We aren't yet ready to talk about arm resolution; for now let's focus on leg names.
256
256
257#### Faces
257#### Faces
258
258
@@ -311,7 +311,7 @@ There is no restriction against using the same face name for multiple limbs of t
3115
3115
312```
312```
313
313
314−Why does this return `5` rather than `6` or `[14 15]`? When a face is evaluated against a subject, a head-first binary tree search occurs starting at address `1` of the subject. If there is no matching face for address `n` of the subject, first the head of `n` is searched and then `n`'s tail. The complete search path for `[[4 b=5] [b=6 b=[14 15]]]` is:
314+Why does this return `5` rather than `6` or `[14 15]`? When a face is evaluated on a subject, a head-first binary tree search occurs starting at address `1` of the subject. If there is no matching face for address `n` of the subject, first the head of `n` is searched and then `n`'s tail. The complete search path for `[[4 b=5] [b=6 b=[14 15]]]` is:
315
315
316
316
317+ `[[4 b=5] [b=6 b=[14 15]]]`
317+ `[[4 b=5] [b=6 b=[14 15]]]`
@@ -388,12 +388,10 @@ How do you get to that `b=2`? And how do you get to the `c` in `[[4 a=5] b=[c=1
388
388
389## Wings
389## Wings
390
390
391−A wing is a search path into the subject, understood as a series of limbs.
392−
393−A wing expression indicates the search path as a series of limb expressions separated by the `.` character.
391+A *wing* is a limb resolution path into the subject. A wing expression indicates the path as a series of limb expressions separated by the `.` character. E.g.,
394
392
395```
393```
396−[limb1].[limb2].[limb3].[and so on....]
394+limb1.limb2.limb3
397```
395```
398
396
399You can read this as `limb1` in `limb2` in `limb3`, etc. You can use a wing to get the value of `c` in `[[4 a=5] b=[c=14 15]]`: `c.b`
397You can read this as `limb1` in `limb2` in `limb3`, etc. You can use a wing to get the value of `c` in `[[4 a=5] b=[c=14 15]]`: `c.b`
@@ -443,9 +441,9 @@ r='howdy'
443
441
444### Limbs are Trivial Wings
442### Limbs are Trivial Wings
445
443
446−As stated before, a wing is a series of limbs indicating a search path into the subject. This definition includes as a trivial case a search path of one limb. Thus, all limbs are wings and all limb expressions are wing expressions.
444+As stated before, a wing is a limb resolution path into the subject. This definition includes as a trivial case a path of just one limb. Thus, all limbs are wings, and all limb expressions are wing expressions.
447
445
448−We mention this because it is convenient to refer to all limbs and non-trivial wings as simply 'wings'. This will be our usual practice for the rest of this tutorial series.
446+We mention this because it is convenient to refer to all limbs and non-trivial wings as simply 'wings'. This will be our usual practice for the rest of this series.
449
447
450## Exploring the Subject
448## Exploring the Subject
451
449
@@ -456,7 +454,7 @@ Earlier we said that every Hoon expression is evaluated relative to a subject.
456'Hello world!'
454'Hello world!'
457```
455```
458
456
459−So, the left uses the product of the right as its subject. But what about the right-hand expression? What's _its_ subject? Until now we've included an explicit subject in all the examples, but it's time to remove the training wheels. Usually the subject of a Hoon expression isn't shown explicitly.
457+The left, `b`, uses the product of the right as its subject. But what about the right-hand expression? What's _its_ subject? Until now we've included an explicit subject in all the examples, but it's time to remove the training wheels. Usually the subject of a Hoon expression isn't shown explicitly.
460
458
461Consider the expression `(add 2 2)`:
459Consider the expression `(add 2 2)`:
462
460
@@ -465,46 +463,46 @@ Consider the expression `(add 2 2)`:
4654
4634
466```
464```
467
465
468−What's its subject?
466+What's the subject of this expression?
469
467
470In fact, you may already know how to find the answer. The subject is a noun and as such its limbs have addresses. To see that noun, use `+1`. You'll see something like the following:
468In fact, you may already know how to find the answer. The subject is a noun and as such its limbs have addresses. To see that noun, use `+1`. You'll see something like the following:
471
469
472```
470```
473> +1
471> +1
474−[ [ our=~mipfyl-lodsel-halrul-dilbyt--balluc-havfes-wordeb-pagrem
472+[ [ our=~zod
475− now=~2018.5.24..23.51.31..f5f2
473+ now=~2018.12.10..22.10.44..09d7
476 eny
474 eny
477− \/0vfq.npac6.eklcb.19rir.el97m.1jaq4.m3ths.ejfa5.cpjiu.fk1uh.kqf9r.jncko.\/
475+ \/0v2dv.6gdve.pp0br.rh1sq.bq4ok.p9dqn.5r44u.7tqrl.qdrmo.i223s.472gv.hrb44\/
478− 7eorl.ciggn.4hi3g.gna8v.qrpvc.rd32q.t60pj.8v7ev.27g2c
476+ .g2h3h.p1dih.3v7ju.58eei.i51es.akbie.290r8.2vt29.qv54q
479 \/ \/
477 \/ \/
480 ]
478 ]
481− ~
479+ <19.anu 24.tmo 6.ipz 38.ard 119.spd 241.plj 51.zox 93.pqh 74.dbd 1.qct $141>
482− <16.swm 19.mtp 41.lur 112.twd 224.bkh 54.tyv 119.wpb 31.ohr 1.jmk $143>
483]
480]
484```
481```
485
482
486−This noun (or a modified version of it) is the subject used for all Hoon expressions entered into the dojo.
483+This noun (or a modified version of it) is the subject used for Hoon expressions entered into the dojo.
487
484
488−We can't explain every part of the subject just yet, but you should be able to recognize some of it. There is a face, `our`, serving as a label for a a comet name. Another face, `now`, is a label for an absolute date. `eny` is a face for an atom serving as [entropy](https://en.wikipedia.org/wiki/Entropy_(computing)). The value for `eny` is different every time it's checked.
485+We can't explain every part of the subject just yet, but you should be able to recognize some of it. There is a face, `our`, serving as a label for the urbit's name. Another face, `now`, is a label for an absolute date. `eny` is a face for an atom serving as [entropy](https://en.wikipedia.org/wiki/Entropy_(computing%29). The value for `eny` is different every time it's checked.
489
486
490```
487```
491> our
488> our
492−~mipfyl-lodsel-halrul-dilbyt--balluc-havfes-wordeb-pagrem
489+~zod
493
490
494> now
491> now
495−~2018.5.24..23.55.34..1ef0
492+~2018.12.10..22.13.25..18ef
496
493
497> eny
494> eny
498−\/0v10v.b4347.pnopi.p2vb4.bohf6.cog4h.m9hld.o2kuq.5pbfg.esrug.1bc0s.u12fo.uit6c\/
495+\/0v3qd.9lnj9.0up6k.dn4tp.ue9cs.mgsii.5fdqm.p12d6.104o1.6knrb.mkft3.pihte.vdt\/
499− .9ets2.g9ssi.kqsg7.j12n3.79aim.d2g3s.aumrs.kis80
496+ bo.io77f.5uq5a.hrish.va34d.jv2b7.3bn3o.ol9ii.fg9i5
500−\/ \/
497+\/ \/
498+
501> eny
499> eny
502−\/0v2q2.va8mn.f6teu.42skq.sc2rh.4p8r6.klrbg.vovm7.7b13l.3tp1g.f33as.7267s.4tj13\/
500+\/0v10n.4lqle.q66jp.rr3uv.3q4nc.dj7pl.t1df4.4a2fe.qh2l5.up998.sj7mp.on646.881\/
503− .p1aa1.um1ee.80fd3.l11b5.sfqen.5aumu.c17vm.3rq45
501+ 0g.nfcfj.gempp.tehbd.087g4.cpi7l.2mr25.477mb.mj2va
504−\/
502+\/ \/
505```
503```
506
504
507−Also embedded in that subject is the Hoon 'standard library', a library of commonly-used functions. We've already used two of them: `add` and `mul`. Have you noticed that these function names look like faces? They aren't faces, but Hoon searches for them like it searches for faces. When we call `add`,
505+Also embedded in that subject is the Hoon 'standard library', a library of commonly-used functions. We've already used two of them: `add` and `mul`. Have you noticed that these function names look like faces? They aren't actually faces, but Hoon searches for them like it searches for faces. When we call `add`,
508
506
509```
507```
510> (add 22 33)
508> (add 22 33)
@@ -528,7 +526,9 @@ It doesn't work because, as far as Hoon is concerned, `add` doesn't exist for th
52855
52655
529```
527```
530
528
529+And it works!
530+
531−And it works! The subject of the right-hand side expression of the `:` is the same implicit subject we have in the dojo.
531+The subject of the right-hand side expression of the `:` is the same implicit subject we have in the dojo.
532
532
533## Dojo Faces
533## Dojo Faces
534
534
@@ -616,7 +616,7 @@ e=20
616[d=15 e=20]
616[d=15 e=20]
617```
617```
618
618
619−### Creating a Modified Leg
619+## Creating a Modified Leg
620
620
621Often a leg of the subject is produced with its value unchanged. But there is a way to produce a modified version of the leg as well. To do so, we use an expression of the form:
621Often a leg of the subject is produced with its value unchanged. But there is a way to produce a modified version of the leg as well. To do so, we use an expression of the form:
622
622
@@ -624,7 +624,7 @@ Often a leg of the subject is produced with its value unchanged. But there is a
624wing-of-subject(wing-1 new-value-1, wing-2 new-value 2, ...)
624wing-of-subject(wing-1 new-value-1, wing-2 new-value 2, ...)
625```
625```
626
626
627−The `wing-of-subject` is a wing path into the subject, followed by a set of parentheses. `wing-1` and `wing-2` are wing paths into the limb indicated by `wing-of subject`, and their values are replaced with `new-value-1` and `new-value-2`, respectively. Commas separate each of the `wing` `new-value` pairs.
627+The `wing-of-subject` resolves to some limb in the subject. This is followed by a set of parentheses. `wing-1` and `wing-2` pick out which parts of that limb we want to change. Their values are replaced with `new-value-1` and `new-value-2`, respectively. Commas separate each of the `wing` `new-value` pairs.
628
628
629Let's create a mutant version of the noun we have stored in `a`. To do this, type in the face `a` followed by the desired modifications in parentheses:
629Let's create a mutant version of the noun we have stored in `a`. To do this, type in the face `a` followed by the desired modifications in parentheses:
630
630
docs/tutorials/hoon-ch1/hoon-ch1-4.udon+122−180
@@ -8,245 +8,212 @@
8
8
9# 1.4 Arms and Cores
9# 1.4 Arms and Cores
10
10
11−The Hoon subject is made up of arms and legs. In the previous lesson you learned what a leg is, and how to return legs of the subject by various means. In this lesson you'll learn what an arm is. Arms are a bit more complex than legs -- a full understanding of them requires a bit more background knowledge. Accordingly, in this lesson we also (1) give a brief overview on Nock, a low-level functional programming language to which Hoon is compiled, and (2) define an important Hoon data structure: 'cores'.
11+The Hoon subject is a noun. Each fragment of this noun is either an arm or a leg. In the previous lesson you learned what a leg is, and how to return legs of the subject by various means. In this lesson you'll learn what an arm is. Arms are a bit more complex than legs -- a full understanding of them requires a bit more background knowledge. Accordingly, in this lesson we must also introduce an important Hoon data structure: a 'core'.
12
12
13−After arms are defined and explained we review wing expressions, this time focusing on wing resolution to arms rather than legs.
13+After arms are defined and explained we review wing expressions, this time focusing on wing resolution to arms.
14
14
15−## Arms: A Preliminary Explanation
15+## A Preliminary Explanation
16
16
17−Arms and legs are limbs of the subject, i.e., noun fragments of the subject. In the last lesson we said that legs are for data and arms are for computations. But what _specifically_ is an arm, and how is it used for computation?
17+Arms and legs are limbs of the subject, i.e., noun fragments of the subject. In the last lesson we said that legs are for data and arms are for computations. But what _specifically_ is an arm, and how is it used for computation? Let's begin with a preliminary explanation that will be refined later in the lesson.
18
18
19−Let's begin with a preliminary definition that will be refined later in the lesson. An *arm* is a Nock formula in the battery of a core.
19+An *arm* is some expression of Hoon encoded as a noun. (By 'encoded as a noun' we literally mean: 'compiled to a Nock formula'. But you don't need to know anything about Nock to understand Hoon.) You virtually never need to treat an arm as raw data, even though technically you can -- it's just a noun like any other. You virtually always want to think of an arm simply as a way of running some Hoon code.
20
20
21−Now you just need to know what a 'Nock formula' is, what a 'battery' is, and what a 'core' is! Read on:
21+Every expression of Hoon is evaluated relative to a subject. What subject is the arm to be evaluated against? Answer: the parent core of that arm.
22
22
23−## Computing Hoon
23+So in order to understand fully what an arm is, you must understand what a core is. Briefly, a *core* is a cell of `[battery payload]`. The *battery* is a collection of one or more arms, and the *payload* is the data needed by the arms to evaluate correctly. (The battery is code and the payload is data for that code.) A given core is the *parent core* of all of the arms in its battery.
24
24
25−Hoon runs on your urbit, which is a virtual computer. However, this virtual computer doesn't directly understand Hoon; it has a Nock interpreter instead. Any Hoon code you want to run must first be compiled to Nock. You certainly don't have to know Nock to understand Hoon, but it helps to be aware of a few of Nock's general features.
25+## Your First Core
26
26
27−Nock is a [low-level](https://en.wikipedia.org/wiki/Low-level_programming_language), [functional programming](https://en.wikipedia.org/wiki/Functional_programming) language. As a consequence Nock itself can be understood as a function, called the 'Nock function'. Nock is officially defined by the [Nock spec](../../nock/definition).
27+To clarify the basic idea, let's look at an example core.
28
28
29−### What is a Function?
29+We'll make a core using a multi-line Hoon expression that is more complex than the other examples you've seen up to this point. The dojo can be used to input multi-line Hoon expressions; just type each line, hitting 'enter' or 'return' at the end. The expression will be evaluated at the appropriate line break, i.e., when the dojo recognizes it as a complete expression of Hoon.
30
30
31−The word 'function' is used in various ways in other programming languages, but we mean it in basically its [mathematical sense](https://en.wikipedia.org/wiki/Function_(mathematics%29). Roughly put, a function takes one or more arguments (i.e., input values) and returns a value. What the return value is depends solely on the argument(s), and nothing else. For example, we can understand multiplication as a function: it takes two numbers and returns another number. It doesn't matter where you ask, when you ask, or what kind of hat you're wearing when you ask. If you pass the same two numbers (e.g., `3` and `4`), you get the same answer returned every time (`12`).
31+Use the following to bind `c` to a core. It begins with a *rune*, `|%`, which is used for creating a core. (A rune is just a pair of ASCII characters, and it usually indicates the beginning of a complex Hoon expression.) Take note of the expression spacing -- Hoon uses significant whitespace. Feel free to cut and paste the following expression into the dojo, starting with `=c`:
32−
33−### The Nock Function
34−
35−The 'Nock function' takes two arguments: (1) a subject, and (2) a Nock formula. The subject is a noun. The formula is, loosely speaking, some instructions encoded as another noun. The Nock function takes those two arguments and returns another noun called the 'product'.
36−
37−The Nock function: `[subject formula] -> product`
38−
39−Here's an example of some Nock run in the dojo, using `.*( )`:
40
32
41```
33```
42−> .*([15 17] [[4 0 2] [0 3]])
34+> =c |%
43−[16 17]
35+ ++ twenty 20
36+ ++ double-twenty (mul 2 twenty)
37+ --
44```
38```
45
39
46−In this example `[15 17]` is the subject, `[[4 0 2] [0 3]]` is the formula, and `[16 17]` is the product.
40+This core has two arms, `twenty` and `double-twenty`. Each arm definition begins with `++` followed by the name of that arm. After that is the Hoon expression associated with that arm. The first expression is the trivial `20` (guess what that does?), and the second is the slightly more interesting `(mul 2 twenty)`.
47
41
48−This tutorial series is designed to teach you Hoon. For that purpose it's not important that you know how to read and understand Nock formulas; you just need to know that Nock takes a subject and a formula and returns a product. (Those who who want to learn more about Nock should head over to the [Nock tutorial](../../nock).)
42+You can run these arms using `twenty.c` and `double-twenty.c`:
49
43
50−### Nock Formulas Define Functions
44+```
45+> twenty.c
46+20
51
47
52−Each Nock formula defines a function of the subject.
48+> double-twenty.c
49+40
50+```
51+
52+Notice that the second arm, `double-twenty`, makes use of the first arm, `twenty`. It's able to do so because each arm is evaluated with its parent core as the subject. Hence, each arm is able to use any other arm inside the parent core's battery.
53
53
54−As stated previously, a Nock formula is just a noun that represents a set of instructions. When the Nock interpreter computes the Nock formula against a subject, the 'instructions' can manipulate and/or modify fragments of the subject, but the instructions have access to no other data. Accordingly, we may think of each Nock formula as defining a function with the subject itself as the argument.
54+### `|%` Expressions
55
55
56−Urbit community members have written Nock formulas for various functions: addition, multiplication, and more. One obsessive individual went overboard and wrote a Nock formula that tests whether a given number is a counterexample to the [Goldbach conjecture](https://en.wikipedia.org/wiki/Goldbach%27s_conjecture).
56+Before moving on let's talk about what each part of the `|%` expression is for.
57
57
58−Keep in mind that Nock is a low-level language. Programming interesting functions in it isn't especially practical. That's why you have Hoon.
58+The `|%` indicates the beginning of an expression that produces a core. The `++` rune is used to define each of the arms of the core's battery, and is followed by both an arm name and a Hoon expression. The `--` rune is used to indicate that there are no more arms to be defined, and indicates the end of the expression.
59
59
60−### Arms are Nock formulas
60+The battery of the core to be produced is explicitly defined by the `|%` expression. The payload of the core to be produced is implicitly defined as the subject of the `|%` expression. Let's unbind `c` to keep the subject clean:
61
61
62−An arm is a _certain kind_ of Nock formula in the battery of a core. Each arm expects the subject to have a certain arrangement so that it can find the data it needs to operate correctly. (This point will be discussed in more detail shortly.) The subject must be a core. What's a core?
62+```
63+> =c
64+```
63
65
64## Cores
66## Cores
65
67
66−A *core* is a cell of a *battery* and a *payload*.
68+Let's go over what a core is a little more carefully and comprehensively. As stated before, a *core* is a cell of a *battery* and a *payload*.
67
69
68```
70```
69A core: [battery payload]
71A core: [battery payload]
70```
72```
71
73
72−Simply put, the battery is code and the payload is data. The payload contains all data necessary for running the code in the battery correctly.
73−
74### Battery
74### Battery
75
75
76−A battery is a cell containing one or more arm(s). That is, a battery is one or more Nock formula(s) that, when computed, expect the subject to be organized as a core. For Hoon programming it's not important to know just how those arms are arranged in the battery. Just keep in mind that this is where the core's computations live.
76+A battery is a collection of arms. An arm is an encoded Hoon expression, to be used for running computations. Each arm has a name. Arm naming rules are the same kebab-case rules that faces have. When an arm is evaluated, it uses its parent core as the subject.
77
77
78−### Payload
78+That's all you really need to know about the battery. You can become a master Hoon programmer if you know what is stated above but otherwise think of the battery as a black box.
79−
80−As stated earlier, the payload is data. In principle, the payload of a core can have data arranged in any arbitrary configuration. In practice, the payload often has a predictable structure of its own.
81
79
82−The payload of a core *C* contains whatever data is necessary to run the arms of *C* correctly. This data may include other cores. Consequently, *C*'s payload data can include other 'code' -- cores in the payload have their own arms.
80+But, if you'd really like to know, technically a battery is a tree of Nock formulas, one formula per each arm. Again, however, you don't need to understand the first thing about Nock to understand Hoon.
83
81
84−### Each Arm Computes with its Parent Core as the Subject
82+### Payload
85−
86−Arms are Nock formulas. But Nock formulas are primitive in many respects. There is no basic Nock operation for looking up face values in the subject, for example. So how do arm 'instructions' find what they need in the subject? The answer is: by assuming that the subject is organized a particular way.
87
83
88−#### Subject Organization for Arm Computation
84+The payload contains all the data needed for running the arms in the battery correctly. In principle, the payload of a core can have data arranged in any arbitrary configuration. In practice, the payload often has a predictable structure of its own.
89
85
90−Up to this point in our dojo examples we haven't organized the subject according to any intentional pattern. The subject for most examples was so small that it wasn't worth the effort to bother with tidying it up.
86+The payload may include other cores. Consequently, a core's payload can include other 'code' -- cores in the payload have their own battery arms.
91
87
92−However, if a subject is sufficiently large and complex -- e.g., it has a standard library of Hoon functions, as the dojo subject does -- then organization becomes a pressing practical matter. It's much better if the subject can be assumed to have a specific, standard arrangement. This is one reason Hoon enforces subject organization for arm computations.
88+### Subject Organization for Arm Computation
93
89
94−The subject must be organized as a core. But not just any core! For an arm to compute correctly, the subject must be the arm's *parent core*.
90+Why must an arm have its parent core as the subject, when it's computed? As stated previously, the payload of a core contains all the data needed for computing the arms of that core. Arms can only access data in the subject. By requiring that the parent core be the subject we guarantee that each arm has the appropriate data available to it, in the tail of the subject. It also allows for making reference to sibling arms in the battery, because they are in the head of the subject.
95
91
96−#### The Parent Core of an Arm
92+Let's look at an example in which the payload information is needed for correct arm evaluation.
97
93
98−Each arm is contained in the battery of a core. That core is the parent core of the arm. In other words: the *parent core* of an arm *A* is the core whose battery contains *A*.
94+## Another Example Core
99
95
100−Why must an arm have its parent core as the subject, when it's computed? As stated previously, the payload of a core contains all the data needed for computing the arms of that core. Remember that arms can only access data in the subject. By requiring that the parent core be the subject we guarantee that each arm has the appropriate data available to it, in the payload.
96+First let's use the dojo to bind the face `a` to the value `12`, and the face `b` to the value `[22 24]`. These values will be used in the arms of the core we're going to make.
101
97
102−An arm can also make use of the other arms in its parent core. This is a useful feature of arms that will be discussed in more detail later.
98+```
99+> =a 12
103
100
104−## Final Definition of an Arm
101+> =b [22 24]
102+```
105
103
106−Now that you have the relevant background knowledge about cores, we can finally give a complete definition of what an arm is.
104+Now use the following multi-line expression to bind `c` to a core. As before, feel free to cut and paste the following expression into the dojo (starting at `=c`):
107
105
108−An arm is a Nock formula in the battery of a core, and it's to be computed with its parent core as the subject.
106+```
107+> =c |%
108+ ++ two 2
109+ ++ inc (add 1 a)
110+ ++ double (mul 2 a)
111+ ++ sum (add -.b +.b)
112+ --
113+```
109
114
110−## Wings that Resolve to Arms
115+Note: binding `c` to the core created by the `|%` expression will fail unless you have already bound `a` and `b` to the relevant values, as we did above. Our having already bound them is what lets us use them in the `|%` expression.
111
116
112−To reinforce your newfound understanding of arms and cores, let's go over various dojo examples illustrating their properties. These examples use and illustrate how wings resolve to arms. Face resolution to a leg of the subject produces the leg value unchanged, but resolution to an arm produces the _computed_ value of that arm.
117+The `|%` expression above creates a core with four arms. The first, named `two`, evaluates to the constant `2`. The second arm, `inc`, adds `1` to `a`. `double` returns double the value of `a`, and `sum` returns the sum of the two atoms in `b`. The computations defined by these arms are pretty simple (and in the case of `two`, trivial), but a good starting point for learning about cores.
113
118
114−To show how this works, we'll look at how the various wing expressions behave when they resolve to arms instead of legs.
119+Let's run the arm names in the dojo:
115
120
116−### Building a Core of Your Own
121+```
122+> two.c
123+2
117
124
118−Before getting to the arm examples we need to produce a simple core. We'll do this using a multi-line Hoon expression that is more complex than the other examples you've seen up to this point. The dojo can be used to input multi-line Hoon expressions; just type each line, hitting 'enter' or 'return' at the end. The expression will be evaluated at the appropriate line break, i.e., when the dojo recognizes it as complete.
125+> inc.c
126+13
119
127
120−First let's use the dojo to bind the face `a` to the value `12`, and the face `b` to the value `[22 24]`. These values will be used in the arms of the core we're going to make. Afterward use `.` to see the value of the subject:
128+> double.c
129+24
121
130
131+> sum.c
132+46
122```
133```
123−> =a 12
124−
125−> =b [22 24]
126
134
127−> .
135+Ideally these wing expressions behave the way you expected!
128−[ [ [a=12 b=[22 24]]
129− our=~bitnus-holleb-rocmeg-fotfer--migsum-nidsym-hilput-patmus
130− now=~2018.8.17..23.53.43..c6b5
131− eny
132− \/0vqg.quub6.1vjms.es43r.rogsb.91okf.bcvtp.eeoih.or9ge.18ere.jtk15.3afb4.5d\/
133− qp2.f7cqj.tj4bh.m7ja9.r1i9m.5scdh.ih7qa.dqm18.q5b4r
134− \/ \/
135− ]
136− ~
137− <16.igq 19.rrs 41.xjd 112.hmp 224.nab 54.tyv 119.wim 31.ohr 1.jmk $143>
138−]
139−```
140
136
141−You can see that `a` and `b` have the desired values in the dojo subject.
137+To reiterate a point made earlier: a wing resolution to a leg returns the value of that leg. A wing resolution to an arm returns the value produced by the arm computation.
142
138
143−#### Using `|%`
139+### Dissecting a Core
144
140
145−Now use the following multi-line expression to bind `c` to a core, then evaluate `c` so you can look at the product. Take note of the expression spacing -- Hoon uses significant whitespace. Feel free to cut and paste the following expression into the dojo:
141+Enter `c` in the dojo to look at this core as printed data:
146
142
147```
143```
148−> =c |%
149− ++ two 2
150− ++ inc (add 1 a)
151− ++ double (mul 2 a)
152− ++ sum (add -.b +.b)
153− --
154−
155> c
144> c
156−< 4.oep
145+< 4.cvq
157 { {{a/@ud b/{@ud @ud}} our/@p now/@da eny/@uvJ}
146 { {{a/@ud b/{@ud @ud}} our/@p now/@da eny/@uvJ}
158− $~
147+ <19.anu 24.tmo 6.ipz 38.ard 119.spd 241.plj 51.zox 93.pqh 74.dbd 1.qct $141>
159− <16.igq 19.rrs 41.xjd 112.hmp 224.nab 54.tyv 119.wim 31.ohr 1.jmk $143>
160 }
148 }
161>
149>
162```
150```
163
151
164−Note: binding `c` to the core created by the `|%` expression will fail unless you have already bound `a` and `b` to the relevant values, as we did above. Our having already bound them is what lets us use them in that expression.
152+`c`, like all cores, is a cell of `[battery payload]`, and it's pretty-printed inside a set of angled brackets: `< >`. The battery of four arms is represented by the pretty-printer as `4.cvq`. The `4` represents the number of arms in the battery, and the `cvq` is a [hash](https://en.wikipedia.org/wiki/Hash_function) of the battery.
165
153
166−`c`, like all cores, is a cell of battery and payload, and it's pretty printed inside a set of angled brackets: `< >`. The battery of four arms is represented by the pretty-printer as `4.oep`. The `4` represents the number of arms in the battery, and the `oep` is a [hash](https://en.wikipedia.org/wiki/Hash_function) of the battery. The tail is a copy of the subject of the `|%` expression (but it's pretty-printed in a slightly different way).
154+The tail, i.e., the payload, might look suspiciously familiar. It looks an awful lot like the default dojo subject, which has `our`, `now`, and `eny` in the head, but it also has `a` and `b`, which we also bound in the dojo subject. That's exactly what the payload is. The tail is a copy of what the subject was for the `|%` expression. (It's pretty-printed in a slightly compressed way).
167
155
168−(You'll notice that there are several other cores in the payload. For example, `16.igq` is a battery of `16` arms, `19.rrs` is a battery of `19` arms, etc.)
156+(You'll notice that there are several other cores in the payload. For example, `19.anu` is a battery of `19` arms, `24.tmo` is a battery of `24` arms, etc.)
169
157
170−#### `|%` Expressions
158+This means, among other things, that we should be able to unbind `a` and `b` in the subject, but the arms of `c` should still work correctly:
171
159
172−We'll cover Hoon syntax thoroughly in lesson 2.2. For now, take for granted that `|%` is a 'rune' used to produce a core. The `++` runes are used to define the arms of the core's battery, and is followed by both an arm name and a computation. The `--` rune is used to indicate that there are no more arms to be defined, and indicates the end of the expression.
160+```
161+> =a
173
162
174−The `|%` expression above creates a core with four arms. The first, named `two`, evaluates to the constant `2`. The second arm, `inc`, adds `1` to `a`. `double` returns double the value of `a`, and `sum` returns the sum of the two atoms in `b`. The computations defined by these arms are pretty simple (and in the case of `two`, trivial), but a good starting point for learning about cores.
163+> =b
175
164
176−#### Payload and Subject
165+> a
166+-find.a
177
167
178−That's enough to specify the battery of the core created by `|%`. But how is the payload defined? The `|%` core payload is simply a copy of the subject of that expression. Remember the subject before we bound `c` to the core?
168+> b
169+-find.b
179
170
180−```
171+> double.c
181−> .
182−[ [ [a=12 b=[22 24]]
172+24
183− our=~bitnus-holleb-rocmeg-fotfer--migsum-nidsym-hilput-patmus
173+
184− now=~2018.8.17..23.53.43..c6b5
174+> sum.c
185− eny
175+46
186− \/0vqg.quub6.1vjms.es43r.rogsb.91okf.bcvtp.eeoih.or9ge.18ere.jtk15.3afb4.5d\/
187− qp2.f7cqj.tj4bh.m7ja9.r1i9m.5scdh.ih7qa.dqm18.q5b4r
188− \/ \/
189− ]
190− ~
191− <16.igq 19.rrs 41.xjd 112.hmp 224.nab 54.tyv 119.wim 31.ohr 1.jmk $143>
192−]
193```
176```
194
177
195−Compare the above with the payload of `c`. We use `+` to look at the tail of `c`:
178+This works because `a` and `b` were copied into the core payload when the core was initially created. Unbinding them in the dojo subject doesn't matter to the arms in `c`, which only look in `c`'s payload anyway.
196
179
197−```
180+The payload stores all the data needed to compute the arms correctly. That also includes `add` and `mul`, which themselves are arms in a core of the Hoon standard library. This library core is available as part of the default dojo subject.
198−> +:c
181+
199−[ [ [a=12 b=[22 24]]
182+## Wings that Resolve to Arms
200− our=~bitnus-holleb-rocmeg-fotfer--migsum-nidsym-hilput-patmus
183+
201− now=~2018.8.17..23.53.43..c6b5
184+To reinforce your newfound understanding of arms and cores, let's go over the various ways that wings resolve to arms in cores. Remember that face resolution to a leg of the subject produces the leg value unchanged, but resolution to an arm produces the _computed_ value of that arm.
202− eny
203− \/0vqk.7dj10.kjlpi.nctqg.mp15l.29i8e.s5228.f7iln.79dl9.onrhn.dtf2i.d3eed.8i\/
204− qvp.0mlff.62tqo.uh6ke.k10hp.kuc76.pj2j5.qclgb.o4niq
205− \/ \/
206− ]
207− ~
208− <16.igq 19.rrs 41.xjd 112.hmp 224.nab 54.tyv 119.wim 31.ohr 1.jmk $143>
209−]
210−```
211
185
212### Address-Based Wings
186### Address-Based Wings
213
187
214−In the last lesson, you saw how the following expressions return legs based on an address in the subject: `+n`, `.`, `-`, `+`, `+>`, `+<`, `->`, `-<`, `&`, `|` etc. When these resolve to the part of the subject containing an arm, they *don't* evaluate the arm. They simply return that fragment of the subject, as if it were a leg.
188+In the last lesson, you saw how the following expressions return legs based on an address in the subject: `+n`, `.`, `-`, `+`, `+>`, `+<`, `->`, `-<`, `&`, `|` etc. When these resolve to the part of the subject containing an arm, they *don't* evaluate the arm. They simply return the indicated noun fragment of the subject, as if it were a leg.
215
189
216Let's use `-.c` to look at the head of `c`, i.e., the battery of the core:
190Let's use `-.c` to look at the head of `c`, i.e., the battery of the core:
217
191
218```
192```
219> -.c
193> -.c
220[ [1 2]
194[ [1 2]
221− [ [8 [9 318 0 2.047] 9 2 [0 4] [[7 [0 3] 1 2] 0 56] 0 11]
195+ [ [8 [9 702 0 2.047] 9 2 10 [6 [7 [0 3] 1 2] 0 56] 0 2]
222 8
196 8
223− [9 8 0 2.047]
197+ [9 20 0 2.047]
224 9
198 9
225 2
199 2
226− [0 4]
200+ 10
227− [[7 [0 3] 1 1] 0 56]
201+ [6 [7 [0 3] 1 1] 0 56]
228 0
202 0
229− 11
203+ 2
230 ]
204 ]
231 8
205 8
232− [9 8 0 2.047]
206+ [9 20 0 2.047]
233 9
207 9
234 2
208 2
235− [0 4]
209+ 10
236− [0 57]
210+ [6 [0 114] 0 115]
237 0
211 0
238− 11
212+ 2
239]
213]
240```
214```
241
215
242−The results is a series of uncomputed Nock formulas. (Don't worry about what they mean -- you don't need to know Nock to become a Hoon expert.) Let's use `-<.c` to look at the head of the head of `c`, i.e., the first arm:
216+The result is a tree of uncomputed Nock formulas. But you virtually never need to see or use this raw data. Generally speaking, don't use address-based expressions to look at arms for any reason other than to satisfy your curiosity (and even then only if you've learned or plan to learn Nock). Use name-based expressions instead.
243−
244−```
245−> -<.c
246−[1 2]
247−```
248−
249−The wing `-<.c` correctly resolves to an arm, but returns the uncomputed Nock formula.
250
217
251### Name-based Wings
218### Name-based Wings
252
219
@@ -261,7 +228,7 @@ To get the arm of a core to compute you must use its name. The arm names of `c`
261 --
228 --
262```
229```
263
230
264−Remember that `a` is `12` and `b` is `[22 24]`. Let's evaluate some arms:
231+We evaluated the arms of `c` previously:
265
232
266```
233```
267> two.c
234> two.c
@@ -277,7 +244,7 @@ Remember that `a` is `12` and `b` is `[22 24]`. Let's evaluate some arms:
27746
24446
278```
245```
279
246
280−You can also evaluate the arms of `c` as follows:
247+You can also evaluate the arms of `c` using `:` instead:
281
248
282```
249```
283> two:c
250> two:c
@@ -293,32 +260,7 @@ You can also evaluate the arms of `c` as follows:
29346
26046
294```
261```
295
262
296−The difference between `two.c` and `two:c` is as follows. `two.c` is an instruction for finding `two` in `c` in the subject. `two:c` is an instruction for setting `c` as the subject, and then finding for `two`. In the examples above both versions amount to the same thing, and so return the same product.
263+The difference between `two.c` and `two:c` is as follows. `two.c` is an instruction for finding `two` in `c` in the subject. `two:c` is an instruction for setting `c` as the subject, and then for finding `two`. In the examples above both versions amount to the same thing, and so return the same product. (There are other cases in which `two.c` and `two:c` _don't_ amount to the same thing. We'll address the difference in more detail later.)
297−
298−What if we unbind `a` and `b` in the dojo subject? Will the arms of `c` still run correctly? Yes.
299−
300−```
301−> =a
302−
303−> =b
304−
305−> a
306−-find.a
307−
308−> inc.c
309−13
310−
311−> sum.c
312−46
313−
314−> a.c
315−12
316−
317−> b.c
318−[22 24]
319−```
320−
321−Notice that `a.c` and `b.c` still evaluate to the values we originally set for `a` and `b`. That's because when we defined `c` those `a` and `b` were stored as part of `c`'s payload. The payload stores all the data needed to compute the arms correctly. That also includes `add` and `mul`, which themselves are arms in a core of the Hoon standard library.
322
264
323### Name Searches and Collisions
265### Name Searches and Collisions
324
266
@@ -337,16 +279,15 @@ When `[double=123 c]` is the subject, the result is a cell of: (1) `double=123`
337```
279```
338> [double=123 c]
280> [double=123 c]
339[ double=123
281[ double=123
340− < 4.oep
282+ < 4.cvq
341 { {{a/@ud b/{@ud @ud}} our/@p now/@da eny/@uvJ}
283 { {{a/@ud b/{@ud @ud}} our/@p now/@da eny/@uvJ}
342− $~
284+ <19.anu 24.tmo 6.ipz 38.ard 119.spd 241.plj 51.zox 93.pqh 74.dbd 1.qct $141>
343− <16.igq 19.rrs 41.xjd 112.hmp 224.nab 54.tyv 119.wim 31.ohr 1.jmk $143>
344 }
285 }
345 >
286 >
346]
287]
347```
288```
348
289
349−Hoon doesn't automatically know whether `double` is a face or an arm name until it conducts a search looking for name matches. If it finds a face first, the value of the face is returned. If it finds an arm first, the arm will be evaluated and the product returned. You may use `^` to indicate that you want to skip the first match, and multiple `^`s to indicate multiple skips:
290+Hoon doesn't know whether `double` is a face or an arm name until it conducts a search looking for name matches. If it finds a face first, the value of the face is returned. If it finds an arm first, the arm will be evaluated and the product returned. You may use `^` to indicate that you want to skip the first match, and multiple `^`s to indicate multiple skips:
350
291
351```
292```
352> double:[double=123 c]
293> double:[double=123 c]
@@ -368,10 +309,9 @@ We can produce a modified version of the core `c` in which `a` and `b` have diff
368
309
369```
310```
370> c(a 99)
311> c(a 99)
371−< 4.oep
312+< 4.cvq
372 { {{a/@ud b/{@ud @ud}} our/@p now/@da eny/@uvJ}
313 { {{a/@ud b/{@ud @ud}} our/@p now/@da eny/@uvJ}
373− $~
314+ <19.anu 24.tmo 6.ipz 38.ard 119.spd 241.plj 51.zox 93.pqh 74.dbd 1.qct $141>
374− <16.igq 19.rrs 41.xjd 112.hmp 224.nab 54.tyv 119.wim 31.ohr 1.jmk $143>
375 }
315 }
376>
316>
377
317
@@ -427,7 +367,7 @@ We can make multiple changes to `c` at once:
427
367
428### Arms on the Search Path
368### Arms on the Search Path
429
369
430−A wing is a search path into the subject. We've looked at some examples of wings that resolve to arms; e.g., `double.c`, which resolves to `double` in `c` in the subject. In the latter example the arm `double` is the final limb in the search path. What if an arm name in a wing isn't the final limb? What if it's elsewhere on the search path?
370+A wing is a search path into the subject. We've looked at some examples of wings that resolve to arms; e.g., `double.c`, which resolves to `double` in `c` in the subject. In the latter example the arm `double` is the final limb in the resolution path. What if an arm name in a wing isn't the final limb? What if it's elsewhere in the wing path?
431
371
432Normally we might read a wing expression like `two.double.c` as '`two` in `double` in `c`'. Does that make sense when `double` is itself an arm? Try it:
372Normally we might read a wing expression like `two.double.c` as '`two` in `double` in `c`'. Does that make sense when `double` is itself an arm? Try it:
433
373
@@ -436,11 +376,11 @@ Normally we might read a wing expression like `two.double.c` as '`two` in `doubl
4362
3762
437```
377```
438
378
439−It produces the value of `two` of `c`. This is a fact in need of explanation.
379+It produces the value of `two` in `c`. This is a fact in need of explanation.
440
380
441−Arms are raw Nock formulas, and there isn't much reason to follow a search path into those. There are no faces or other names in arm Nock formulas! For this reason, when arm names are included in the search path the search behavior is a little different. Instead of indicating that the search should continue in the arm itself, an arm name indicates that the search should continue in the parent core of the arm.
381+When arm names are included in the body of a wing, the resolution behavior is a little different from that of legs. Instead of indicating that the wing resolution should continue in the arm itself, an arm name indicates that the resolution should continue in the parent core of the arm.
442
382
443−So the meaning of `two.double.c` is, roughly, '`two` in the parent core of `double` in `c`'. Of course, Hoon doesn't know that `double` is an arm until the search for it ends; but once the `double` arm is found, Hoon continues the search from _the parent core of_ `double`, not `double` itself. It turns out in this case that this is a redundant step. `c` is the parent core and was already on the search path. We can illustrate redundancy more dramatically:
383+So the meaning of `two.double.c` is, roughly, '`two` in the parent core of `double` in `c`'. Of course, Hoon doesn't know that `double` is an arm until the search for it ends; but once the `double` arm is found, Hoon continues the resolution from _the parent core of_ `double`, not `double` itself. It turns out in this case that this is a redundant step. `c` is the parent core and was already in the wing path. We can illustrate redundancy more dramatically:
444
384
445```
385```
446> double.two.sum.two.double.inc.c
386> double.two.sum.two.double.inc.c
@@ -467,6 +407,8 @@ Assume `this.is.a.wing` is a wing that resolves to an arm. You can use the `thi
46756
40756
468```
408```
469
409
410+This almost looks like a function call of sorts.
411+
470## Summary
412## Summary
471
413
472At this point you should have a pretty good understanding of what an arm is, and how wing resolution to an arm works. But so far the arms you've created have been fairly simple. In the next lesson you'll learn about Hoon functions, and how to create your own.
414At this point you should have a pretty good understanding of what an arm is, and how wing resolution to an arm works. But so far the arms you've created have been fairly simple. In the next lesson you'll learn about Hoon functions, and how to create your own.
docs/tutorials/hoon-ch1/hoon-ch1-5.udon+1−1
@@ -24,7 +24,7 @@ You've already used two functions from the Hoon standard library: `add` and `mul
24
24
25A core is a cell: `[battery payload]`.
25A core is a cell: `[battery payload]`.
26
26
27−A gate is a core, but it's not just any core. It has two distinctive properties: (1) the battery of a gate contains exactly one arm, which has the special name `$`; and (2) the payload of a gate consists of a cell of `[sample context]`. The sample is the part of the payload that stores the 'argument' (i.e., input value) of the function call. The context contains all other data that is needed for computing the `$` arm of the gate correctly.
27+A gate is a core, but it's not just any core. It has two distinctive properties: (1) the battery of a gate contains exactly one arm, which has the special name `$`. The `$` arm contains the instructions for the function in question. And (2), the payload of a gate consists of a cell of `[sample context]`. The sample is the part of the payload that stores the 'argument' (i.e., input value) of the function call. The context contains all other data that is needed for computing the `$` arm of the gate correctly.
28
28
29```
29```
30A gate: [$ [sample context]]
30A gate: [$ [sample context]]
docs/tutorials/hoon-ch1/hoon-ch1-6.udon+3−3
@@ -101,7 +101,7 @@ Notice that each arm in core `c` is able to call the other arms of `c` -- `add-t
101
101
102### The `..arm` Syntax
102### The `..arm` Syntax
103
103
104−Let's say you have a wing that resolves to a leg of the subject. In this wing is an arm name, e.g., `a.b.arm`. As you know from lesson 1.3, this should be read as '`a` in `b` in the parent core of `arm`'. Speaking more directly: the wing search path goes through the parent core of the arm, not the arm itself.
104+Let's say you have a wing that resolves to a leg of the subject. In this wing is an arm name, e.g., `a.b.arm`. As you know from lesson 1.4, this should be read as '`a` in `b` in the parent core of `arm`'. Speaking more directly: the wing resolution path goes through the parent core of the arm, not the arm itself.
105
105
106Recall that `.` by itself returns the whole subject. With that in mind, take a moment to answer the following question on your own. In general, what should the expression `..arm` produce?
106Recall that `.` by itself returns the whole subject. With that in mind, take a moment to answer the following question on your own. In general, what should the expression `..arm` produce?
107
107
@@ -135,7 +135,7 @@ For an example of this, consider the `add` arm of the Hoon standard library. Th
135
135
136```
136```
137> ..add
137> ..add
138−<31.ohr 1.jmk $143>
138+<74.dbd 1.qct $141>
139```
139```
140
140
141Here you see a core with a battery of 31 arms, and whose payload is another core with one arm.
141Here you see a core with a battery of 31 arms, and whose payload is another core with one arm.
@@ -204,7 +204,7 @@ Let's look once more at the parent core of the `add` arm in the Hoon standard li
204
204
205```
205```
206> ..add
206> ..add
207−<31.ohr 1.jmk $143>
207+<74.dbd 1.qct $141>
208```
208```
209
209
210The battery of this core contains 31 arms, each of which evaluates to a gate in the standard library. This 'library' is nothing more than a core containing useful basic functions that Hoon often makes available as part of the subject. You can see the Hoon code defining these arms near the beginning of [hoon.hoon](https://github.com/urbit/arvo/blob/master/sys/hoon.hoon), starting with [`++ add`](https://github.com/urbit/arvo/blob/master/sys/hoon.hoon#L21). (Yes, the Hoon standard library is written in Hoon.)
210The battery of this core contains 31 arms, each of which evaluates to a gate in the standard library. This 'library' is nothing more than a core containing useful basic functions that Hoon often makes available as part of the subject. You can see the Hoon code defining these arms near the beginning of [hoon.hoon](https://github.com/urbit/arvo/blob/master/sys/hoon.hoon), starting with [`++ add`](https://github.com/urbit/arvo/blob/master/sys/hoon.hoon#L21). (Yes, the Hoon standard library is written in Hoon.)