on master help sign in
nesting contexts
commit3be9fbc6e0f682aa7dc4afb5580949b4f522a344 authorJONATHAN PAPROCKI <jon@tlon.io> dateFri 5 Jun 2020, 14:25 (6 years ago) parentbc78fd9
1 file changed+21−2
tutorials/hoon/arms-and-cores.md+21−2
tutorials/hoon/arms-and-cores.md+21−2
@@ -492,6 +492,16 @@ Again, being able to read Nock is not essential to understanding Hoon.
492492
493493Let's take a quick look at how cores can be combined with `=>` to build up larger structures. `=> p=hoon q=hoon` allows you to take the product of `q` with the product of `p` taken as the subject.
494494
495+We can use this to set the context of cores. For example:
496+```
497+~zod:dojo> =>([1 2] |=(@ 15))
498+<1.fed {@ @ud @ud}>
499+```
500+Here we have created a gate that takes in an `@` and returns `15` with `[1 2]`
501+as its context.
502+
503+`=>` (and its reversed version `=<`) are used extensively to put cores into the
504+context of other cores.
495505```hoon
496506=>
497507|%
@@ -505,7 +515,14 @@ Let's take a quick look at how cores can be combined with `=>` to build up large
505515 (mul (foo a) 2)
506516--
507517```
508−In this core, `foo` is in the subject of `bar`, and so `bar` is able to call `foo`. On the other hand, `bar` is not in the subject of `foo`, so `foo` cannot call `bar` - you will get a `-find.bar` error.
518+At the level of arms, `+foo` is in the subject of `+bar`, and so `+bar` is able to call `+foo`. On the other hand, `+bar` is not in the subject of `+foo`, so `+foo` cannot call `+bar` - you will get a `-find.bar` error.
519+
520+It is also helpful to think about what is happening on the level of cores here.
521+The `=>` here sets the context of the core containing `+bar` to be the core
522+containing `+foo`. Recall that arms are evaluated with the parent core as the
523+subject. Thus `+bar` is evaluated with the core containing it as the subject,
524+which has the core containing `+foo` in its context. So this is why `+foo` is in
525+the scope of `+bar` but not vice versa.
509526
510527Let's take a look inside of `hoon.hoon`, where the standard library is located, to see how this is being used.
511528
@@ -606,7 +623,9 @@ Lastly, let's check the subject of the last arm in `hoon.hoon` (as of November 2
606623This confirms for us, then, that `hoon.hoon` consists of six nested cores, with the `hoon-version` core at the top.
607624
608625#### Exercise 1.7a
609−Pick a couple of arms in `hoon.hoon` and check to make sure that they are only referenced in the layer they exist in or a deeper layer. This is easily accomplished with `Ctrl-F`.
626+Pick a couple of arms in `hoon.hoon` and check to make sure that they are only
627+referenced in its parent core or core(s) that have the parent core put in its
628+context via the `=>` or `=<` runes.
610629
611630## Casts
612631