on master help sign in
update 1.9
d8621cctinnus-napbus
content/docs/hoon/hoon-school/generators.md+13−14
@@ -16,9 +16,8 @@ There are three kinds of generators: naked, `%say`, and `%ask`. There also used
16### Naked Generators
16### Naked Generators
17
17
18A naked generator is simply a `gate`; that is, it is an anonymous function that
18A naked generator is simply a `gate`; that is, it is an anonymous function that
19−takes a `sample` (argument) and produces a [noun](/docs/glossary/noun/). All you need to do is write a
19+takes a `sample` (argument) and produces a [noun](/docs/glossary/noun/). All you
20−`gate` and put it into a file in the `/gen` directory. Let's take a look at a
20+need to do is write a `gate` and put it into a file in the `/gen` directory of a desk on your ship. Let's take a look at a very simple one:
21−very simple one:
22
21
23```hoon
22```hoon
24|= a=*
23|= a=*
@@ -26,7 +25,8 @@ a
26```
25```
27
26
28This generator takes one argument of any noun and produces it without any
27This generator takes one argument of any noun and produces it without any
28+changes. Put this into a file named `echo.hoon` in the `/gen` directory of your
29−changes. Once you put this into a file named `echo.hoon` in the `/gen` directory, you must make your ship recognize the change by inputting `|commit %home` in the dojo. You can then run it from the dojo:
29+`%base` desk. You must make your ship recognize the change by inputting `|commit %base` in the dojo. You can then run it from the dojo:
30
30
31```
31```
32> +echo 42
32> +echo 42
@@ -64,7 +64,7 @@ generator to see something more familiar:
64```
64```
65
65
66Now let's create a generator with two arguments instead of one. Save the code
66Now let's create a generator with two arguments instead of one. Save the code
67−below as `add.hoon` in the `/gen` directory.
67+below as `add.hoon` in the `/gen` directory of your `%base` desk.
68
68
69```hoon
69```hoon
70|= [a=@ud b=@ud]
70|= [a=@ud b=@ud]
@@ -104,7 +104,7 @@ So, more formally, a `%say` generator is a `cell`. The head of that cell is the
104output data and the `mark` describing that data.
104output data and the `mark` describing that data.
105
105
106Below is an example of a `%say` generator. Save it to `add.hoon` in the `/gen`
106Below is an example of a `%say` generator. Save it to `add.hoon` in the `/gen`
107−directory.
107+directory of your `%base` desk.
108
108
109```hoon
109```hoon
110:- %say
110:- %say
@@ -133,7 +133,7 @@ Recall that the rune `:-` produces a cell, with the first following expression
133as its head and the second following expression as its tail.
133as its head and the second following expression as its tail.
134
134
135The expression above creates a cell with `%say` as the head. The tail is
135The expression above creates a cell with `%say` as the head. The tail is
136−the `|= *` expression on the line that follows.
136+the `|= *` expression on the line that follows.
137
137
138```hoon
138```hoon
139|= *
139|= *
@@ -141,10 +141,10 @@ the `|= *` expression on the line that follows.
141(add 40 2)
141(add 40 2)
142```
142```
143
143
144−`|= *` constructs a [gate](/docs/glossary/gate/) that takes a noun. This [gate](/docs/glossary/gate/) will itself produce a
144+`|= *` constructs a [gate](/docs/glossary/gate/) that takes a noun. This [gate](/docs/glossary/gate/) will itself produce a
145`cask`, which is cell formed by the prepending `:-`. The head of that `cask` is
145`cask`, which is cell formed by the prepending `:-`. The head of that `cask` is
146`%noun` and the tail is the rest of the program, `(add 40 2)`. The tail of the
146`%noun` and the tail is the rest of the program, `(add 40 2)`. The tail of the
147−`cask` will be our actual data produced by the body of the program: in this
147+`cask` will be our actual data produced by the body of the program: in this
148case, just adding 40 and 2 together.
148case, just adding 40 and 2 together.
149
149
150#### `%say` generators with arguments
150#### `%say` generators with arguments
@@ -216,7 +216,7 @@ second part, besides its position:
216```
216```
217
217
218Let's look at an example that uses all three parts. Save the code below in a
218Let's look at an example that uses all three parts. Save the code below in a
219−file called `dice.hoon` in your `/gen` directory.
219+file called `dice.hoon` in the `/gen` directory of your `%base` desk.
220
220
221```hoon
221```hoon
222:- %say
222:- %say
@@ -311,7 +311,7 @@ to explain how this kind of generator works.
311##### `%ask` example
311##### `%ask` example
312
312
313The code below is an `%ask` generator that checks if the user inputs "blue" when
313The code below is an `%ask` generator that checks if the user inputs "blue" when
314−prompted. Save it as `axe.hoon` in `/gen`.
314+prompted. Save it as `axe.hoon` in the `/gen` directory of your `%base` desk.
315
315
316```hoon
316```hoon
317/- sole
317/- sole
@@ -379,7 +379,7 @@ This code might be familiar. Just as with their `%say` cousins, `%ask`
379generators need to produce a `cell`, the head of which specifies what kind of
379generators need to produce a `cell`, the head of which specifies what kind of
380generator we are running.
380generator we are running.
381
381
382−With `|= *`, we create a gate and ignore the standard arguments we are given,
382+With `|= *`, we create a gate and ignore the standard arguments we are given,
383because we're not using them.
383because we're not using them.
384
384
385```hoon
385```hoon
@@ -434,7 +434,6 @@ use to prompt the user. In the case of our example, we use `"color: "`.
434**`produce`** is used to construct the output of the generator. In our example,
434**`produce`** is used to construct the output of the generator. In our example,
435we produce a `tang`.
435we produce a `tang`.
436
436
437−
438```hoon
437```hoon
439|= t=tape
438|= t=tape
440```
439```
@@ -458,4 +457,4 @@ This is a [known issue](https://github.com/urbit/arvo/issues/840) to be resolved
458
457
459## Conclusion
458## Conclusion
460
459
461−You've now reached the end of Chapter 1 of the Hoon tutorial. Ideally you should have a fair understanding of the fundamental concepts of subject-oriented programming: limbs, legs, faces, wings, arms, cores, gates, and [doors](/docs/glossary/door/). If you can master these concepts you should have little or no trouble learning to write substantial Hoon programs.
460+You've now reached the end of Chapter 1 of the Hoon tutorial. Ideally you should have a fair understanding of the fundamental concepts of subject-oriented programming: limbs, legs, faces, wings, arms, cores, gates, and [doors](/docs/glossary/door/). If you can master these concepts you should have little or no trouble learning to write substantial Hoon programs.