@@ -11,7 +11,7 @@ Hoon isn't an object-oriented programming language; it's a "subject-oriented" pr
12For now we can say three things about the subject: (1) every Hoon expression is evaluated relative to some subject; (2) roughly, the subject defines the environment in which a Hoon expression is evaluated; and (3) the subject is a noun.
12For now we can say three things about the subject: (1) every Hoon expression is evaluated relative to some subject; (2) roughly, the subject defines the environment in which a Hoon expression is evaluated; and (3) the subject is a noun.
14−In fact, you already created some subjects in lesson 1.2 when you used `+` to return a fragment of a noun:
14+In fact, you already learned about the noun address system in [Lesson 1.2](../nouns.md) when you used `+` to return a fragment of a noun:
17> +1:[[11 22] 33]
17> +1:[[11 22] 33]
@@ -58,7 +58,7 @@ Let's create a subject with some computations:
59## Limbs of the Subject
59## Limbs of the Subject
61−The subject is a noun, just like any other piece of Hoon data. In the last lesson we discussed how any noun can be understood as a binary tree. E.g., `[[4 5] [6 [14 15]]]`:
61+The subject is a noun, just like any other piece of Hoon data. In Lesson 1.2 we discussed how any noun can be understood as a binary tree. E.g., `[[4 5] [6 [14 15]]]`:
64 [[4 5] [6 [14 15]]]
64 [[4 5] [6 [14 15]]]
@@ -79,7 +79,7 @@ Sometimes a programmer simply wants to produce a value from the subject. In oth
80### Address-based Limb Expressions
80### Address-based Limb Expressions
82−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.)
82+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.
84In 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.
84In 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.
@@ -176,6 +176,27 @@ You can think of this sort of lark series -- e.g., `+>-<` -- as indicating a bin
176 *Head* Tail
176 *Head* Tail
180+1. Use a lark expression to obtain the value 6 in the following noun represented by a binary tree:
196+2. Use a lark expression to obtain the value 9 in the following noun: `[[5 6] 7 [[8 9 10] 3] 2] 1]`.
198+Solutions to these exercises may be found at the bottom of this lesson.
179#### `&` and `|` operators
200#### `&` and `|` operators
181`&n` returns the `n`th item of a list that has at least `n + 1` items. `|n` returns everything after `&n`.
202`&n` returns the `n`th item of a list that has at least `n + 1` items. `|n` returns everything after `&n`.
@@ -223,9 +244,9 @@ The list items can themselves be cells:
223['third' %pair]
244['third' %pair]
226−We can give an alternate, recursive definition of `&n` for all positive integers `n`. In the base case, `&1` is equivalent to `+2`. For the generating case, assume that `&(n - 1)` is equivalent to `+k`. Then `&n` is equivalent to `+((k x 2) + 2)`.
247+We can give an alternate, recursive definition of `&n` for all positive integers `n`. In the base case, `&1` is equivalent to `+2`. For the generating case, assume that `&(n - 1)` is equivalent to `+k`. Then `&n` is equivalent to `+((k × 2) + 2)`.
228−For example, let `n` be 4. What is `&4`? `&3` is equivalent to `+14`. `(14 x 2) + 2` is `30`, so `&4` is equivalent to `+30`.
249+For example, let `n` be 4. What is `&4`? `&3` is equivalent to `+14`. `(14 × 2) + 2` is `30`, so `&4` is equivalent to `+30`.
230`|n` returns the rest of the list after `&n`:
251`|n` returns the rest of the list after `&n`:
@@ -243,7 +264,7 @@ For example, let `n` be 4. What is `&4`? `&3` is equivalent to `+14`. `(14 x
246−As with `&n`, we can characterize `|n` recursively. In the base case, `|1` is `+3`. In the generating case, assume that `|(n - 1)` is equivalent to `+k`. Then `|n` is equivalent to `+((k x 2) + 1)`.
267+As with `&n`, we can characterize `|n` recursively. In the base case, `|1` is `+3`. In the generating case, assume that `|(n - 1)` is equivalent to `+k`. Then `|n` is equivalent to `+((k × 2) + 1)`.
248### Other Limb Expressions: Names
269### Other Limb Expressions: Names
@@ -654,3 +675,52 @@ You can also use more complex wings and modify their values as well:
655At this point you should have at least a rough idea of what the subject is, and a fair understanding of how to get legs of the subject using wings. But legs are only one kind of limb -- we'll talk about arms in the next lesson.
676At this point you should have at least a rough idea of what the subject is, and a fair understanding of how to get legs of the subject using wings. But legs are only one kind of limb -- we'll talk about arms in the next lesson.
679+Enter the following into dojo:
681+=a [[[b=%bweh a=%.y c=8] b="no" c="false"] 9]
683+Test your knowledge from this lesson by evaluating the following expressions and then checking your answer in the dojo or see the solutions below.
685+1. `> b:a(a [b=%skrt a="four"])`
686+2. `> ^b:a(a [b=%skrt a="four"])`
687+3. `> ^^b:a(a [b=%skrt a="four"])`
688+4. `> b.a:a(a [b=%skrt a="four"])`
689+5. `> a.a:a(a [b=%skrt a="four"])`
690+6. `+.a:a(a [b=%skrt a="four"])`
691+7. `a:+.a:a(a [b=%skrt a="four"])`
694+10. How many times does the atom `9` appear in `a(a a(a a))`?
696+## Exercise Solutions
701+> =b [[[5 6 7] 8 9] 10 11 12 13]
707+> =c [[5 6] 7 [[8 9 10] 3] 2]
715+3. Error: `ford: %slim failed:`
718+6. `a="four"` - Note that this is different from the above!
720+8. `[[[b=%bweh a=[[[b=%bweh a=%.y c=8] b="no" c="false"] 9] c=8] b="no" c="false"]9]`
722+10. `9` appears 3 times:
725+[[[ b=%bweh a [[[b=%bweh a=[[[b=%bweh a=%.y c=8] b="no" c="false"] 9] c=8] b="no" c="false"] 9] c=8] b="no" c="false"] 9]