on master help sign in
updated info about cores
commit9fcd07012067aeb3d35728db47d41579cd7361ba authorDavid Kerschner <dkerschner@hcoop.net> dateTue 2 Jul 2019, 11:59 (7 years ago) parent89b95e1
1 file changed+69
learn/hoon/hoon-tutorial/arms-and-cores.md+69
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.