on master help sign in
Merge branch 'david-draft' into rob-edits-3
commitcb5f4c27564dd03707aaa397a99026d65ea44baa authorDavid Kerschner <david@tlon.io> dateTue 2 Jul 2019, 12:58 (7 years ago) parentaaeb8759fcd070
3 files changed+75−1
learn/hoon/hoon-tutorial/arms-and-cores.md+69 learn/hoon/hoon-tutorial/iron-polymorphism.md+5−1 learn/hoon/hoon-tutorial/libraries.md+1
learn/hoon/hoon-tutorial/arms-and-cores.md+69
@@ -404,6 +404,75 @@ Assume `this.is.a.wing` is a wing that resolves to an arm. You can use the `thi
404404
405405This almost looks like a function call of sorts.
406406
407+
408+### Cores, Gates, and Traps
409+
410+Let's take a quick look at the battery of one core in the dojo to show that this is true by inputting one into the dojo.
411+
412+```
413+> =dec |%
414+ ++ dec
415+ |= a=@
416+ ?< =(0 a)
417+ =+ b=0
418+ |- ^- @
419+ ?: =(a +(b)) b
420+ $(b +(b))
421+ --
422+
423+```
424+
425+This core has one arm `dec` which implements decrement. If we look at the head of the core we'll see the Nock.
426+
427+```
428+> -:dec
429+[ 8
430+ [1 0]
431+ [ 1
432+ 6
433+ [5 [1 0] 0 6]
434+ [0 0]
435+ 8
436+ [1 0]
437+ 8
438+ [1 6 [5 [0 30] 4 0 6] [0 6] 9 2 10 [6 4 0 6] 0 1]
439+ 9
440+ 2
441+ 0
442+ 1
443+ ]
444+ 0
445+ 1
446+]
447+```
448+
449+Again, being able to read Nock is not essential to understanding Hoon.
450+
451+Let's take a quick look at how cores can be combined to build up larger structures.
452+
453+```
454+=>
455+|%
456+++ dec
457+ |= a=@
458+ ?< =(0 a)
459+ =+ b=0
460+ |- ^- @
461+ ?: =(a +(b)) b
462+ $(b +(b))
463+--
464+|%
465+++ add
466+ |= [a=@ b=@]
467+ ^- @
468+ ?: =(0 a) b
469+ $(a (dec a), b +(b))
470+--
471+```
472+
473+Here you can see the style of wrapping one core in another. This technique is used frequently in Hoon, particularly in the standard library. `dec` is used in the subsequent core. This can be a useful code organization technique. Gates and Traps are both special kinds of cores, as you will see in later lessons.
474+
475+
407476## Summary
408477
409478At 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.
learn/hoon/hoon-tutorial/iron-polymorphism.md+5−1
@@ -54,6 +54,7 @@ Lets look at two examples of using `fold`.
5454
5555Here we have a call to `fold` that we can see will produce a `(list @)` from a list of `@`. The first argument is a cell of `~` and `~[1 2 3 4]`.
5656
57+
5758The gate will simply add two to each element `e` and append that to the front of `s`. Let's run this in the `dojo`:
5859
5960```
@@ -64,6 +65,7 @@ The gate will simply add two to each element `e` and append that to the front of
6465 :_ s
6566 (add 2 e)
6667~[6 5 4 3]
68+
6769~zod:dojo>
6870```
6971
@@ -71,6 +73,7 @@ The list is in reverse order simply because it's easier to add to the front of a
7173
7274But `fold` does not have to produce a `list`. Let's look at another example:
7375
76+
7477```
7578%+ (fold @ @)
7679 [0 ~[1 2 3 4]]
@@ -78,9 +81,10 @@ But `fold` does not have to produce a `list`. Let's look at another example:
7881(add e s)
7982```
8083
84+
8185Here `fold` will produce a gate that takes an `atom` and applies a gate to a `list` of `atoms`. The difference here is that this call will produce a sum of the elements of the list, rather than the list itself.
8286
8387The key takeaway from both of these examples is that the gates provided are _iron polymorphic_ with respect to the definition of the type in `fold`. They are iron polymorphic because samples `s` and `e` nest under the types `state` and `elem`. In second case case, that's because when we provided those to `fold`, it was was stated they were `@` and `@`. In the first case, we stated that `state` was `(list @)` and `elem` was `@`. In both cases, the sample of each gate nest inside the types defined when we called the wet gate `fold`.
8488
8589
86−[Next Up: Reading -- Gall](../gall)
90+[Next Up: Reading -- Gall](../gall)
learn/hoon/hoon-tutorial/libraries.md+1
@@ -164,6 +164,7 @@ This is a very naive shuffling algorithm, and you could imagine a better one. Im
164164
165165## Using the Library
166166
167+
167168So now that we have this library, how do we actually use it? Let's look at a very simple `say` generator that takes advantage of what we built.
168169
169170```