@@ -15,23 +15,22 @@ Threads are managed by the gall agent called `spider`.
16## Thread location
16## Thread location
18−Threads live in the `ted` directory of your desk:
18+Threads live in the `ted` directory of each desk. For example, in a desk named `%sandbox`:
30 │ └──bar.hoon
29 │ └──bar.hoon
31 └──baz.hoon
30 └──baz.hoon
34−From the dojo, `ted/baz.hoon` can be run with `-baz`, and `ted/foo/bar.hoon` with `-foo-bar`.
33+From the dojo, `ted/baz.hoon` can be run with `-sandbox!baz`, and `ted/foo/bar.hoon` with `-sandbox!foo-bar`. Threads in the `%base` desk can just be run like `-foo`, but all others must have the format `-desk!thread`.
36**NOTE:** When the dojo sees the `-` prefix it automatically handles creating a thread ID, composing the argument, poking the `spider` gall agent and subscribing for the result. Running a thread from another context (eg. a gall agent) requires doing these things explicitly and is outside the scope of this particular tutorial.
35**NOTE:** When the dojo sees the `-` prefix it automatically handles creating a thread ID, composing the argument, poking the `spider` gall agent and subscribing for the result. Running a thread from another context (eg. a gall agent) requires doing these things explicitly and is outside the scope of this particular tutorial.
@@ -57,7 +56,7 @@ That is, a gate which takes a `vase` and returns the `form` of a `strand` that p
58
57
60−This is because threads typically do a bunch of I/O so it can't just immediately produce a result and end. Instead the strand will get some input, produce output, get some new input, produce new output, and so forth, until they eventually produce a `%done` with the actual final result.
59+This is because threads typically do a bunch of I/O so it can't just immediately produce a result and end. Instead the strand will get some input, produce output, get some new input, produce new output, and so forth, until they eventually produce a `%done` with the actual final result.
@@ -66,9 +65,10 @@ Strands are the building blocks of threads. A thread will typically compose mult
66A strand is a function of `strand-input:strand -> output:strand` and is defined in `/lib/strand/hoon`. You can see the details of `strand-input` [here](https://github.com/urbit/urbit/blob/master/pkg/arvo/lib/strand.hoon#L2-L21) and `output:strand` [here](https://github.com/urbit/urbit/blob/master/pkg/arvo/lib/strand.hoon#L23-L48). At this stage you don't need to know the nitty-gritty but it's helpful to have a quick look through. We'll discuss these things in more detail later.
65A strand is a function of `strand-input:strand -> output:strand` and is defined in `/lib/strand/hoon`. You can see the details of `strand-input` [here](https://github.com/urbit/urbit/blob/master/pkg/arvo/lib/strand.hoon#L2-L21) and `output:strand` [here](https://github.com/urbit/urbit/blob/master/pkg/arvo/lib/strand.hoon#L23-L48). At this stage you don't need to know the nitty-gritty but it's helpful to have a quick look through. We'll discuss these things in more detail later.
68A strand is a core that has three important arms:
67A strand is a core that has three important arms:
69- `form` - the mold of the strand
69- `form` - the mold of the strand
70- `pure` - produces a strand that does nothing except return a value
70- `pure` - produces a strand that does nothing except return a value
71−- `bind` - monadic bind, like `then` in javascript promises
71+- `bind` - monadic bind, like `then` in javascript promises
73We'll discuss each of these arms later.
73We'll discuss each of these arms later.
@@ -81,7 +81,7 @@ Strands are conventionally given the face `m` like:
84−**NOTE:** a comma prefix as in `,vase` is the irregular form of `^:` which is a gate that returns the sample value if it's of the correct type, but crashes otherwise.
84+**NOTE:** a comma prefix as in `,vase` is the irregular form of `^:` which is a gate that returns the sample value if it's of the correct type, but crashes otherwise.
86## Form and Pure
86## Form and Pure
@@ -104,12 +104,12 @@ We'll cover `bind` later.
104## A trivial thread
104## A trivial thread
107−/- spider
107+/- spider
108−=, strand=strand:spider
108+=, strand=strand:spider
109−^- thread:spider
109+^- thread:spider
110−|= arg=vase
110+|= arg=vase
111−=/ m (strand ,vase)
111+=/ m (strand ,vase)
112−^- form:m
112+^- form:m
113(pure:m arg)
113(pure:m arg)
@@ -117,7 +117,6 @@ The above code is a simple thread that just returns its argument, and it's a goo
118Save the above code as a file in `ted/mythread.hoon` and `|commit` it. Run it with `-mythread 'foo'`, you should see the following:
118Save the above code as a file in `ted/mythread.hoon` and `|commit` it. Run it with `-mythread 'foo'`, you should see the following:
122> -mythread 'foo'
121> -mythread 'foo'
@@ -130,8 +129,8 @@ Save the above code as a file in `ted/mythread.hoon` and `|commit` it. Run it wi
130We'll go through it line-by line.
129We'll go through it line-by line.
133−/- spider
132+/- spider
134−=, strand=strand:spider
133+=, strand=strand:spider
137First we import `/sur/spider/hoon` which includes `/lib/strand/hoon` and give give the latter the face `strand` for convenience.
136First we import `/sur/spider/hoon` which includes `/lib/strand/hoon` and give give the latter the face `strand` for convenience.
@@ -155,7 +154,7 @@ We create a gate that takes a vase, the first part of the previously mentioned t
155Inside the gate we create our `strand` specialised to produce a `vase` and give it the canonical face `m`.
154Inside the gate we create our `strand` specialised to produce a `vase` and give it the canonical face `m`.
158−^- form:m
157+^- form:m
161We cast the output to `form` - the mold of the strand we created.
160We cast the output to `form` - the mold of the strand we created.