on master help sign in
update thread fundaments wrt dist
5c00035tinnus-napbus
content/docs/userspace/threads/basics/fundamentals.md+16−17
@@ -15,23 +15,22 @@ Threads are managed by the gall agent called `spider`.
15
15
16## Thread location
16## Thread location
17
17
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`:
19
19
20```
20```
21−%
21+%sandbox
22├──app
22├──app
23├──gen
23├──gen
24├──lib
24├──lib
25├──mar
25├──mar
26├──sur
26├──sur
27−├──sys
28└──ted <-
27└──ted <-
29 ├──foo
28 ├──foo
30 │ └──bar.hoon
29 │ └──bar.hoon
31 └──baz.hoon
30 └──baz.hoon
32```
31```
33
32
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`.
35
34
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.
37
36
@@ -57,7 +56,7 @@ That is, a gate which takes a `vase` and returns the `form` of a `strand` that p
57
56
58![thread diagram](https://storage.googleapis.com/media.urbit.org/site/thread-diagram.png "diagram of a thread")
57![thread diagram](https://storage.googleapis.com/media.urbit.org/site/thread-diagram.png "diagram of a thread")
59
58
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.
61
60
62## Strands
61## Strands
63
62
@@ -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.
67
66
68A strand is a core that has three important arms:
67A strand is a core that has three important arms:
68+
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
72
72
73We'll discuss each of these arms later.
73We'll discuss each of these arms later.
74
74
@@ -81,7 +81,7 @@ Strands are conventionally given the face `m` like:
81...
81...
82```
82```
83
83
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.
85
85
86## Form and Pure
86## Form and Pure
87
87
@@ -104,12 +104,12 @@ We'll cover `bind` later.
104## A trivial thread
104## A trivial thread
105
105
106```hoon
106```hoon
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)
114```
114```
115
115
@@ -117,7 +117,6 @@ The above code is a simple thread that just returns its argument, and it's a goo
117
117
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:
119
119
120−
121```
120```
122> -mythread 'foo'
121> -mythread 'foo'
123[~ 'foo']
122[~ '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.
131
130
132```hoon
131```hoon
133−/- spider
132+/- spider
134−=, strand=strand:spider
133+=, strand=strand:spider
135```
134```
136
135
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`.
156
155
157```hoon
156```hoon
158−^- form:m
157+^- form:m
159```
158```
160
159
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.