on master help sign in
copy fixes
commitb15f4c43182471a57c8cd72af8d2cdafc246910e authorRobert <robert@tlon.io> dateTue 19 Mar 2019, 11:46 (8 years ago) parenta519033
2 files changed+13−14
learn/arvo/workbook/list.udon+9−10 learn/arvo/workbook/recursion.udon+4−4
learn/arvo/workbook/list.udon+9−10
@@ -7,7 +7,7 @@
77
88# List of Numbers
99
10−This code-example is intended to familiarize you with the basics of Hoon syntax. It's okay if you don't understand everything immediately; some concepts concepts may beyond your grasp for now. What's important is that you familiarize yourself with the elements of the code and their look once combined into a valid program.
10+This code-example is intended to familiarize you with the basics of Hoon syntax. It's okay if you don't understand everything immediately; some concepts may beyond your grasp for now. What's important is that you become accustomed to the elements of the code and their look once combined into a valid program.
1111
1212Below is a simple Hoon program that takes a single number `n` from the user as input and produces a list of numbers from `1` up to (but not including) `n`. So, if the user gives the number `5`, the program will produce: `~[1 2 3 4]`.
1313
@@ -27,7 +27,7 @@ The easiest way to use such a program is to run it as a _generator_. Saving a fi
2727
2828`~your-ship:> +list 5`
2929
30−Try it! You can choose any number, but this kind of program requires a number after the `+list` command to work. the `+` lets the Dojo know that it's looking for a generator with the name that follows.
30+Try it! You can choose any natural number to put after `+list`, but it can't be zero or blank. The `+` lets the Dojo know that it's looking for a generator with the name that follows.
3131
3232But what do all these squiggly symbols in the program _do_? It probably isn't immediately clear. Let's go through each component of this code.
3333
@@ -43,7 +43,7 @@ In our example program, we use comments with line numbers for convenient referen
4343|= end=@
4444```
4545
46−There's a few things going on in our first line. The first part of it, `|=` is a kind of *rune*. Runes are the building blocks of all Hoon code, represented as a pair of non-alphanumeric ASCII characters. Runes form expressions; runes are used how keywords are used in other languages. In other words, all computations in Hoon ultimately require runes. Runes, and other expressions, are all separated from one another by either two spaces or a line break.
46+There's a few things going on in our first line. The first part of it, `|=`, is a kind of *rune*. Runes are the building blocks of all Hoon code, represented as a pair of non-alphanumeric ASCII characters. Runes form expressions; runes are used how keywords are used in other languages. In other words, all computations in Hoon ultimately require runes. Runes and other Hoon expressions are all separated from one another by either two spaces or a line break.
4747
4848All runes take a fixed number of "children." Children can themselves be runes with children, and Hoon programs work by chaining through these until a value -- not another rune -- is arrived at. Keep this scheme in mind when examining Hoon code.
4949
@@ -53,7 +53,7 @@ Because we're only on line 1, all we're doing with the gate is creating it, and
5353
5454Our program is simple, so the _entire program_ is the gate that's being created here. The rest of our lines of code are part of the second child of our gate, and they determine how our gate produces an output.
5555
56−## Line 2
56+### Line 2
5757
5858```
5959=/ count=@ 1
@@ -65,7 +65,7 @@ This line begins with the `=/` rune, which stores a value with a name and specif
6565
6666We're using `count` to keep track of what numbers we're adding to the list we're building. We'll use it later in the program.
6767
68−## Line 3
68+### Line 3
6969
7070```
7171|-
@@ -73,7 +73,7 @@ We're using `count` to keep track of what numbers we're adding to the list we're
7373
7474The `|-` rune functions as a "restart" point for recursion that will be defined later. It takes one child.
7575
76−## Line 4
76+### Line 4
7777
7878```
7979^- (list @)
@@ -83,7 +83,7 @@ The `^-` rune constrains output to a certain type. It takes two children.
8383
8484In this case, the rune specifies that our gate's output must be `(list @)` -- that is, a list of atoms.
8585
86−## Lines 5 and 6
86+### Lines 5 and 6
8787
8888```
8989?: =(end count)
@@ -108,10 +108,9 @@ In our case, `:- count` creates a cell out of whatever value is stored in `coun
108108$(count (add 1 count))
109109```
110110
111−
112111The above code is, once again, a compact way of writing a rune expression. All you need to know is that this line of code restarts the program at `|-`, except with the value stored in `count` incremented by 1. The construction of `(count (add 1 count))` tells the computer, "replace the value of count with count+1".
113112
114−You'll notice that we use an unfamiliar word here: `add`. Unlike `count` and `end`, `add` is not defined anywhere else in the program. That's because it's a gate that's predefined in the Hoon *standard library*. The standard library is filled with pre-defined gates that are generally useful, and these gates can be used just like something that you named in your own program.
113+You'll notice that we use an unfamiliar word here: `add`. Unlike `count` and `end`, `add` is not defined anywhere in our program. That's because it's a gate that's predefined in the Hoon *standard library*. The standard library is filled with pre-defined gates that are generally useful, and these gates can be used just like something that you defined in your own program.
115114
116115## Explanation
117116
@@ -133,4 +132,4 @@ Our program works by having each iteration of the list creating a cell. In each
133132 4 ~
134133```
135134
136−If you don't immediately intuit how this is working, don't worry. We'll take a deeper look into recursion later with our [Recursion example](../recursion).
135+If you still don't intuit how this is working, don't worry. We'll take a deeper look into recursion later with our [Recursion example](../recursion).
learn/arvo/workbook/recursion.udon+4−4
@@ -7,7 +7,7 @@
77
88# Recursion
99
10−Recursion is a common pattern for solving certain problems in many programming
10+Recursion is a common pattern for solving certain problems in most programming
1111languages, and Hoon is no exception. One of the classically recursive problems
1212is that of factorial. The factorial of _n_ is the product of all positive
1313integers less than or equal to N. Thus the factorial of 5, denoted as _5!_,
@@ -56,7 +56,7 @@ Let's run the program in the Dojo:
5656120
5757```
5858
59−It may help to visualize the operation our example gate. The pseudo-Hoon below
59+It may help to visualize the operation of our example gate. The pseudo-Hoon below
6060illustrates what happens when we use it to find the factorial of 5:
6161
6262```
@@ -74,7 +74,7 @@ illustrates what happens when we use it to find the factorial of 5:
7474
7575It's easy to see how we're "floating" gate calls until we reach the final
7676iteration of such calls that only produces a value. The `mul n` component of the
77−gate leaves something like `mul 5`, waiting for the a final series of terms
77+gate leaves something like `mul 5`, waiting for the final series of terms
7878to be operated upon. The `$(n (dec n))` component is what expands out the
7979expression, as illustrated by `(factorial 4)`. Once the expression cannot be
8080expanded out further, the operations work backwards, successively feeding values
@@ -176,7 +176,7 @@ each iteration can be replaced instead of held in memory.
176176
177177##### A Note on `$`
178178
179−`$` is, in its use with recursion, a reference to the gate that we are inside
179+`$` (pronounced "buc") is, in its use with recursion, a reference to the gate that we are inside
180180of. That's because a gate is just a core with a single arm named `$`. The
181181subject is searched depth-first, head before tail, with faces skipped, and
182182stopping on the first result. In other words, the first match found in the head