on master help sign in
minor fixes to list.udon
commit1a30ccbcc2b39f2524a9f4aa9b4dd3535f098f7b authorRobert <robert@tlon.io> dateMon 4 Mar 2019, 10:54 (8 years ago) parent1c82bdf
1 file changed+18−2
learn/arvo/workbook/list.udon+18−2
learn/arvo/workbook/list.udon+18−2
@@ -9,7 +9,7 @@
99
1010This code-example is intended to familiarize you with the basics of Hoon syntax. It's ok if you don't understand everything immediately. Some concepts might be beyond your understanding for now. What's important that you familiarize yourself with the elements of the code and their look once combined into a valid program.
1111
12−Below 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]`.
12+Below 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
1414
1515```
@@ -117,4 +117,20 @@ You'll notice that we use an unfamiliar word here: `add`. Unlike `count` and `en
117117
118118If you aren't intuiting how the program is building the list, that's okay.
119119
120−Our program works by each iteration of the list creating a cell. In each iteration, the head of the cell -- its first position -- is filled with the current-iteration value of `count`. The tail of the cell, its second position, is filled with _the product of a new iteration of our code_ starting at `|-`. This iteration will create another cell, the head of which will be filled by the incremented value of `count`, and the tail of which will start another iteration. This process continues until `?:` branches to `~`, and the list is terminated. So, a built-out list of nested cells can be visualized like this: `[1 [2 [3 [4 ~]]]]`.
120+Our program works by having each iteration of the list creating a cell. In each of these cells, the head -- the cell's first position -- is filled with the current-iteration value of `count`. The tail of the cell, its second position, is filled with _the product of a new iteration of our code_ that starts at `|-`. This iteration will itself create another cell, the head of which will be filled by the incremented value of `count`, and the tail of which will start another iteration. This process continues until `?:` branches to `~` (null). When that happens, the list is terminated and the program doesn't have anything else to do, so it ends. So, a built-out list of nested cells can be visualized like this:
121+
122+```
123+ [1 [2 [3 [4 ~]]]]
124+
125+ .
126+ / \
127+ 1 .
128+ / \
129+ 2 .
130+ / \
131+ 3 .
132+ / \
133+ 4 ~
134+```
135+
136+If you don't immediately intuit how this is working, that's ok. We'll take a deeper look into recursion later.