@@ -210,6 +210,52 @@ is `[14 15]`
211Hopefully this isn't terribly hard to follow.
211Hopefully this isn't terribly hard to follow.
213+### Editing a Noun, `#`
217+#[(a + a) b c] #[a [b /[(a + a + 1) c]] c]
218+#[(a + a + 1) b c] #[a [/[(a + a) c] b] c]
221+The `#` operator replaces part of a noun with another noun. `#[x y z]` replaces address `x` of `z` with the noun `y`.
223+Take some noun, say, `[22 33 44 55]`. Let's replace part of it with another noun, `[123 456]`. We can replace the entire original noun as follows:
226+#[1 [123 456] [22 33 44 55]]
235+If we only want to replace the value at address `2`:
238+#[2 [123 456] [22 33 44 55]]
247+And we can replace address `3`:
250+#[3 [123 456] [22 33 44 55]]
213## Instructions
259## Instructions
215These rules define Nock itself - ie, the `*` operator.
261These rules define Nock itself - ie, the `*` operator.
@@ -227,6 +273,7 @@ Note that we're using Hoon syntax here. Since we do not use Nock
227from Hoon all that often (it's sort of like embedding assembly in
273from Hoon all that often (it's sort of like embedding assembly in
228C), we've left it a little cumbersome. In Hoon, instead of
274C), we've left it a little cumbersome. In Hoon, instead of
229writing `*[a 0 b]`, we write
275writing `*[a 0 b]`, we write
231.*(a [0 b])
278.*(a [0 b])
@@ -281,10 +328,10 @@ This gives the same `[153 218]`
282*[a 3 b] ?*[a b]
329*[a 3 b] ?*[a b]
283*[a 4 b] +*[a b]
330*[a 4 b] +*[a b]
284−*[a 5 b] =*[a b]
331+*[a 5 b c] =[*[a b] *[a c]]
287−In lines 23-25, we meet our axiomatic functions again:
334+These are axiomatic functions:
289For instance, if `x` is a formula that calculates some product,
336For instance, if `x` is a formula that calculates some product,
290`[4 x]` calculates that product plus one. Hence:
337`[4 x]` calculates that product plus one. Hence:
@@ -322,7 +369,7 @@ We could write this line less formally:
322In other words, if you have two Nock formulas `x` and `y`, a
369In other words, if you have two Nock formulas `x` and `y`, a
323formula that computes the pair of them is just `[x y]`. We can
370formula that computes the pair of them is just `[x y]`. We can
324recognize this because no atom is a valid formula, and
371recognize this because no atom is a valid formula, and
325−every formula that *does not* use line 19 has an atomic head.
372+every formula that *does not* use distribution has an atomic head.
327If you know Lisp, you can think of this feature as a sort of
374If you know Lisp, you can think of this feature as a sort of
328"implicit cons." Where in Lisp you would write `(cons x y)`,
375"implicit cons." Where in Lisp you would write `(cons x y)`,
@@ -353,45 +400,45 @@ we get
356−Except for the crash defaults (lines 6, 10, 17, and 35), we've actually
403+Except for the crash defaults, we've actually
357completed all the _essential_ aspects of Nock. The instructions up
404completed all the _essential_ aspects of Nock. The instructions up
358through 5 provide all necessary computational functionality.
405through 5 provide all necessary computational functionality.
359Nock, though very simple, is actually much more complex than it
406Nock, though very simple, is actually much more complex than it
360formally needs to be.
407formally needs to be.
362−Operators 6 through 10 are macros. They exist because Nock is
409+Operators 6 through 11 are sugar. They exist because Nock is
363not a toy, but a practical interpreter. Let's see them all
410not a toy, but a practical interpreter. Let's see them all
366−## Macros
413+## Sugar
369−*[a 6 b c d] *[a 2 [0 1] 2 [1 c d] [1 0] 2 [1 2 3] [1 0] 4 4 b]
416+*[a 6 b c d] *[a *[[c d] 0 *[[2 3] 0 *[a 4 4 b]]]]
370−*[a 7 b c] *[a 2 b 1 c]
417+*[a 7 b c] *[*[a b] c]
371−*[a 8 b c] *[a 7 [[7 [0 1] b] 0 1] c]
418+*[a 8 b c] *[[*[a b] a] c]
372−*[a 9 b c] *[a 7 c 2 [0 1] 0 b]
419+*[a 9 b c] *[*[a c] 2 [0 1] 0 b]
373−*[a 10 [b c] d] *[a 8 c 7 [0 3] d]
420+*[a 10 [b c] d] #[b *[a c] *[a d]]
422+*[a 11 [b c] d] *[[*[a c] *[a d]] 0 3]
374−*[a 10 b c] *[a c]
423+*[a 11 b c] *[a c]
377−Notice that instructions `6` through `10` are macros: each just
378−expands to a larger formula. Let's try to figure out what these
426+Let's try to figure out what these do, simplest first:
379−macros do, simplest first:
381−### `10`, hint
428+### `11`, hint
384−*[a 10 b c] *[a c]
431+*[a 11 b c] *[a c]
387If `x` is an atom and `y` is a formula, the formula `[10 x y]`
434If `x` is an atom and `y` is a formula, the formula `[10 x y]`
388appears to be equivalent to... `y`. For instance:
435appears to be equivalent to... `y`. For instance:
391−.*([132 19] [10 37 [4 0 3]])
438+.*([132 19] [11 37 [4 0 3]])
394−Why would we want to do this? `10` is actually a hint instruction.
441+Why would we want to do this? `11` is actually a hint instruction.
395The `37` in this example is discarded information - it is not
442The `37` in this example is discarded information - it is not
396used, formally, in the computation. It may help the interpreter
443used, formally, in the computation. It may help the interpreter
397compute the expression more efficiently, however.
444compute the expression more efficiently, however.
@@ -403,13 +450,13 @@ the Nock spec. Some are defined in Hoon. Indeed, a naive Nock
403interpreter not optimized for Hoon will run Hoon quite poorly.
450interpreter not optimized for Hoon will run Hoon quite poorly.
404When it gets the product, however, the product will be right.
451When it gets the product, however, the product will be right.
406−There is another instruction `10` rule:
453+There is another instruction `11` rule:
409−*[a 10 [b c] d] *[a 8 c 7 [0 3] d]
456+*[a 11 [b c] d] *[[*[a c] *[a d]] 0 3]
412−Once we see what `7` and `8` do, we'll see that this complex hint
459+This complex hint
413throws away an arbitrary `b`, but computes the formula `c`
460throws away an arbitrary `b`, but computes the formula `c`
414against the subject and... throws away the product. This formula
461against the subject and... throws away the product. This formula
415is simply equivalent to `d`. Of course, in practice the product
462is simply equivalent to `d`. Of course, in practice the product
@@ -418,12 +465,12 @@ wind up as a side effect.
419(Why do we even care that `c` is computed? Because `c` could
466(Why do we even care that `c` is computed? Because `c` could
420crash. A correct Nock cannot simply ignore it, and treat both
467crash. A correct Nock cannot simply ignore it, and treat both
421−variants of `10` as equivalent.)
468+variants of `11` as equivalent.)
423### `7`, compose
470### `7`, compose
426−*[a 7 b c] *[a 2 b 1 c]
473+*[a 7 b c] *[*[a b] c]
429Suppose we have two formulas, `b` and `c`. What is the formula
476Suppose we have two formulas, `b` and `c`. What is the formula
@@ -435,13 +482,13 @@ Suppose we have two formulas, `b` and `c`. What is the formula
437Good old composition, on Nock formulas. It's easy to see how
484Good old composition, on Nock formulas. It's easy to see how
438−this is built out of `2`. The data to evaluate is simply `b`,
485+this is a variant of Nock `2`. The data to evaluate is simply `b`,
439and the formula is `c` quoted.
486and the formula is `c` quoted.
441### `8`, extend
488### `8`, extend
444−*[a 8 b c] *[a 7 [[7 [0 1] b] 0 1] c]
491+*[a 8 b c] *[[*[a b] a] c]
447`8` is `7`, except that the subject for `c` is not simply the
494`8` is `7`, except that the subject for `c` is not simply the
@@ -464,22 +511,16 @@ likely to generate an `8`, because the variable is computed
464against the present subject, and used in a calculation which
511against the present subject, and used in a calculation which
465depends both on the original subject and the new variable.
512depends both on the original subject and the new variable.
467−For extra credit, explain why we can't just define
470−*[a 8 b c] *[a 7 [b 0 1] c]
473### `9`, invoke
514### `9`, invoke
475`9` is a calling convention:
516`9` is a calling convention:
478−*[a 9 b c] *[a 7 c 2 [0 1] 0 b]
519+*[a 9 b c] *[*[a c] 2 [0 1] 0 b]
481With `c`, we produce a noun which contains both code and data - a
522With `c`, we produce a noun which contains both code and data - a
482−*core*. We use this core as the subject, and evaulate the
523+*core*. We use this core as the subject, and evaluate the
483formula within it at slot `b`.
524formula within it at slot `b`.
485### `6`, if-then-else
526### `6`, if-then-else
@@ -487,7 +528,7 @@ formula within it at slot `b`.
487This looks much scarier than it is:
528This looks much scarier than it is:
490−*[a 6 b c d] *[a 2 [0 1] 2 [1 c d] [1 0] 2 [1 2 3] [1 0] 4 4 b]
531+*[a 6 b c d] *[a *[[c d] 0 *[[2 3] 0 *[a 4 4 b]]]]
493If `b` evaluates to `0`, we produce `c`; if `b` evaluates to `1`,
534If `b` evaluates to `0`, we produce `c`; if `b` evaluates to `1`,