on master help sign in
Updated gates to include "looping" and link to recursion doc.
commit0d9ce994d885930348a29509573f0954f4dcee37 authorDavid Kerschner <dkerschner@hcoop.net> dateWed 8 May 2019, 15:27 (7 years ago) parent9e93e5f
2 files changed+35−2
learn/hoon/hoon-tutorial/gates.udon+35−2 learn/hoon/workbook/recursion.udon → learn/hoon/hoon-tutorial/recursion.udon
learn/hoon/hoon-tutorial/gates.udon+35−2
@@ -256,12 +256,45 @@ We can use `ten(b 25)` to produce a variant of `ten`. Calling this mutant versi
256256175
257257```
258258
259−Before finishing the lesson let's unbind `ten`:
259+Let's unbind `ten`:
260260
261261```
262262> =ten
263263```
264264
265+## Looping
266+
267+Let's examine a new gate.
268+
269+```
270+|= [a=@ud b=@ud]
271+=| c=@ud
272+|-
273+?: =(b 0)
274+ c
275+$(c (add a c), b (dec b))
276+```
277+
278+This gate takes two arguments and multiplies them together using only `add` and `dec` This is an extremely naive way to do multiplication but let's examine it anyway.
279+
280+The first thing worth noticing is the new rune `|-` which you can think of as a looping structure. We're denoting some bit of code that we want to run multiple times. This is a lie but go with it for a moment.
281+
282+The next few lines should be pretty clear, if `b` is `0` we're going to return `c`.
283+When it isn't, we are going to use the irregular form of the `%=` rune, the wide form of this line would look like this.
284+
285+```
286+%=($ c (add a c), b (dec b))
287+```
288+
289+What this rune does is resolve a wing with changes. In this case, and in many you will see, the wing we want to resolve is `$` or the `|-` we are inside. The rest are a set of changes to make to the subject of that wing. We are going to add `a` to `c` and decrement `b` and then run the code again starting from `|-`.
290+
291+In the next lesson, we'll examine `|-` in more detail.
292+
293+### Jets
294+
295+Hoon code is compiled to Nock and Nock is extremely simple and naive in the way a number of things are done. For example, the only mathematical operation Nock has is increment. All other mathematical functions are built out of this. While this is conceptually doable, actually running this code could be unnecessarily slow. This is the reason for jets, a set of functionally identical code that could be run instead of the compiled Nock to speed up execution. To learn more about Jets see [jets doc].
296+
297+
265298## Exercise 1.5.1 Solution
266299
267300Write a gate that takes an atom, `a=@`, and which returns double the value of `a`. Bind this gate to `double` and test it in the dojo.
@@ -276,4 +309,4 @@ Write a gate that takes an atom, `a=@`, and which returns double the value of `a
27630950
277310```
278311
279−### [Next Lesson: Multi-gate Cores and Doors](../multi-gate-cores-and-doors)
312+### [Recursion](../recursion)
learn/hoon/workbook/recursion.udon → learn/hoon/hoon-tutorial/recursion.udonrenamed

The content is the same.