@@ -18,124 +18,124 @@ Let's take a look at two apps, `:source` and `:sink`. First,
1818`:source`:
1919
2020```
21− :: Sends subscription updates to sink.hoon
22− ::
23− :::: /===/app/source/hoon
24− ::
25− !:
26− ::
27− |%
28− +$ move [bone card]
29− +$ card $% [%diff diff-contents]
30− ==
31− +$ diff-contents $% [%noun *]
32− ==
33− --
34− ::
35− |_ [bow=bowl:gall $~]
36− ::
37− ++ poke-noun
38− |= non=*
39− ^- [(list move) _+>.$]
40− :_ +>.$
41− %+ turn (prey /example-path bow)
42− |=({o=bone *} [o %diff %noun non])
43− ::
44− ++ peer-example-path
45− |= pax/path
46− ^- [(list move) _+>.$]
47− ~& source+peer-notify+'Someone subscribed to you!'
48− ~& source+[ship+src.bow path+pax]
49− [~ +>.$]
50− ::
51− ++ coup
52− |= {wir=wire err=(unit tang)}
53− ^- [(list move) _+>.$]
54− ?~ err
55− ~& source+success+'Poke succeeded!'
21+:: Sends subscription updates to sink.hoon
22+::
23+:::: /===/app/source/hoon
24+ ::
25+!:
26+::
27+|%
28+ +$ move [bone card]
29+ +$ card $% [%diff diff-contents]
30+ ==
31++$ diff-contents $% [%noun *]
32+ ==
33+--
34+::
35+|_ [bow=bowl:gall $~]
36+::
37+++ poke-noun
38+ |= non=*
39+ ^- [(list move) _+>.$]
40+ :_ +>.$
41+ %+ turn (prey /example-path bow)
42+ |=({o=bone *} [o %diff %noun non])
43+::
44+++ peer-example-path
45+ |= pax/path
46+ ^- [(list move) _+>.$]
47+ ~& source+peer-notify+'Someone subscribed to you!'
48+ ~& source+[ship+src.bow path+pax]
5649 [~ +>.$]
57− ~& source+error+'Poke failed. Error:'
58− ~& source+error+err
59− [~ +>.$]
60− ::
61− ++ reap
62− |= [wir=wire err=(unit tang)]
63− ^- [(list move) _+>.$]
64− ?~ err
65− ~& source+success+'Peer succeeded!'
50+::
51+++ coup
52+ |= {wir=wire err=(unit tang)}
53+ ^- [(list move) _+>.$]
54+ ?~ err
55+ ~& source+success+'Poke succeeded!'
56+ [~ +>.$]
57+ ~& source+error+'Poke failed. Error:'
58+ ~& source+error+err
59+ [~ +>.$]
60+::
61+++ reap
62+ |= [wir=wire err=(unit tang)]
63+ ^- [(list move) _+>.$]
64+ ?~ err
65+ ~& source+success+'Peer succeeded!'
66+ [~ +>.$]
67+ ~& source+error+'Peer failed. Error:'
68+ ~& source+error+err
6669 [~ +>.$]
67− ~& source+error+'Peer failed. Error:'
68− ~& source+error+err
69− [~ +>.$]
70− ::
71− --
70+::
71+--
7272```
7373
7474And secondly, `:sink`:
7575
7676```
77− :: Sets up a simple subscription to source.hoon
78− ::
79− :::: /===/app/sink/hoon
80− ::
81− !:
82− |%
83− +$ move [bone card]
84− +$ card $% [%peer wire dock path]
85− [%pull wire dock $~]
86− ==
87− --
88− ::
89− |_ [bow=bowl:gall val=?]
90− ::
91− ++ poke-noun
92− |= non=*
93− ^- [(list move) _+>.$]
94− ?: &(=(%on non) val)
95− :_ +>.$(val |)
96− :~ :* ost.bow
77+:: Sets up a simple subscription to source.hoon
78+::
79+:::: /===/app/sink/hoon
80+ ::
81+!:
82+|%
83++$ move [bone card]
84++$ card $% [%peer wire dock path]
85+ [%pull wire dock $~]
86+ ==
87+--
88+::
89+|_ [bow=bowl:gall val=?]
90+::
91+++ poke-noun
92+ |= non=*
93+ ^- [(list move) _+>.$]
94+ ?: &(=(%on non) val)
95+ :_ +>.$(val |)
96+ :~ :* ost.bow
9797 %peer
9898 /subscribe
9999 [our.bow %source]
100100 /example-path
101101 ==
102− ==
103− ?: &(=(%off non) !val)
104− :_ +>.$(val &)
105− ~[[ost.bow %pull /subscribe [our.bow %source] ~]]
106− ~& ?: val
107− sink+unsubscribed+'You are now unsubscribed!'
108− sink+subscribed+'You are now subscribed!'
109− [~ +>.$]
110− ::
111− ++ diff-noun
112− |= [wir=wire non=*]
113− ^- [(list move) _+>.$]
114− ~& sink+received-data+'You got something!'
115− ~& sink+data+non
116− [~ +>.$]
117− ::
118− ++ coup
119− |= [wir=wire err=(unit tang)]
120− ^- [(list move) _+>.$]
121− ?~ err
122− ~& sink+success+'Poke succeeded!'
102+ ==
103+ ?: &(=(%off non) !val)
104+ :_ +>.$(val &)
105+ ~[[ost.bow %pull /subscribe [our.bow %source] ~]]
106+ ~& ?: val
107+ sink+unsubscribed+'You are now unsubscribed!'
108+ sink+subscribed+'You are now subscribed!'
123109 [~ +>.$]
124− ~& sink+error+'Poke failed. Error:'
125− ~& sink+error+err
126− [~ +>.$]
127− ::
128− ++ reap
129− |= [wir=wire err=(unit tang)]
130− ^- [(list move) _+>.$]
131− ?~ err
132− ~& sink+success+'Peer succeeded!'
110+::
111+++ diff-noun
112+ |= [wir=wire non=*]
113+ ^- [(list move) _+>.$]
114+ ~& sink+received-data+'You got something!'
115+ ~& sink+data+non
133116 [~ +>.$]
134− ~& sink+error+'Peer failed. Error:'
135− ~& sink+error+err
136− [~ +>.$]
137− ::
138− --
117+::
118+++ coup
119+ |= [wir=wire err=(unit tang)]
120+ ^- [(list move) _+>.$]
121+ ?~ err
122+ ~& sink+success+'Poke succeeded!'
123+ [~ +>.$]
124+ ~& sink+error+'Poke failed. Error:'
125+ ~& sink+error+err
126+ [~ +>.$]
127+::
128+++ reap
129+ |= [wir=wire err=(unit tang)]
130+ ^- [(list move) _+>.$]
131+ ?~ err
132+ ~& sink+success+'Peer succeeded!'
133+ [~ +>.$]
134+ ~& sink+error+'Peer failed. Error:'
135+ ~& sink+error+err
136+ [~ +>.$]
137+::
138+--
139139```
140140
141141Two notes:
@@ -147,32 +147,39 @@ Two notes:
147147Here's some sample output of the two working together:
148148
149149```
150− ~fintud-macrep:dojo> |start %source
151− >=
152− ~fintud-macrep:dojo> |start %sink
153− >=
154− ~fintud-macrep:dojo> :sink %on
155− [%source %peer-notify 'Someone subscribed to you!']
156− [%source [%ship ~fintud-macrep] %path /]
157− [%sink %success 'Peer succeeded!']
158− >=
159− ~fintud-macrep:dojo> :source 5
160− [%sink %received-data 'You got something!']
161− [%sink %data 5]
162− >=
163− ~fintud-macrep:dojo> :sink %off
164− >=
165− ~fintud-macrep:dojo> :source 6
166− >=
167− ~fintud-macrep:dojo> :sink %on
168− [%source %peer-notify 'Someone subscribed to you!']
169− [%source [%ship ~fintud-macrep] %path /]
170− [%sink %success 'Peer succeeded!']
171− >=
172− ~fintud-macrep:dojo> :source 7
173− [%sink %received-data 'You got something!']
174− [%sink %data 7]
175− >=
150+~fintud-macrep:dojo> |start %source
151+>=
152+
153+~fintud-macrep:dojo> |start %sink
154+>=
155+
156+~fintud-macrep:dojo> :sink %on
157+[%source %peer-notify 'Someone subscribed to you!']
158+[%source [%ship ~fintud-macrep] %path /]
159+[%sink %success 'Peer succeeded!']
160+>=
161+
162+~fintud-macrep:dojo> :source 5
163+[%sink %received-data 'You got something!']
164+[%sink %data 5]
165+>=
166+
167+~fintud-macrep:dojo> :sink %off
168+>=
169+
170+~fintud-macrep:dojo> :source 6
171+>=
172+
173+~fintud-macrep:dojo> :sink %on
174+[%source %peer-notify 'Someone subscribed to you!']
175+[%source [%ship ~fintud-macrep] %path /]
176+[%sink %success 'Peer succeeded!']
177+>=
178+
179+~fintud-macrep:dojo> :source 7
180+[%sink %received-data 'You got something!']
181+[%sink %data 7]
182+>=
176183```
177184
178185### :source
@@ -190,8 +197,8 @@ Our definition of `move` is fairly specific, since we're only going to
190197sending one kind of move. The `%diff` move is a subscription update, and
191198its content is marked data which gall routes to our subscribers.
192199
193−This is a slightly different kind of move than [we've dealt with so
194−far](/arvo/network). It's producing a result rather than calling other
200+This is a slightly different kind of move than we've dealt with so
201+far. It's producing a result rather than calling other
195202code (i.e. it's a return rather than a function call), so if you recall
196203the discussion of ducts, a layer gets popped off the duct rather than
197204added to it. This is why no wire is needed for the move -- we won't
@@ -227,7 +234,7 @@ that begins with the given path. "Prey" is short for "prefix".
227234Now we have the list of relevant subscribers. This a list of triples,
228235`{bone @p path}`, where the only thing we really need is the bone, because we
229236don't need to know their urbit or what exact path they subscribed on. Thus, our
230−transformer function takes `{o/bone *}` and produces `[o %diff %noun non]`,
237+transformer function takes `[o=bone *]` and produces `[o %diff %noun non]`,
231238which is a move that provides bone `o` with this subscription update:
232239`[%noun non]`". This is fairly dense code, but what it's doing is
233240straightforward!
@@ -251,7 +258,7 @@ your bone and wire are the same as when you subscribed, then the cancellation
251258will happen correctly.
252259
253260The only state we need for `:sink` is a boolean to indicate whether
254−we're already subscribed to `:source`. We use `val/?`, where `?`
261+we're already subscribed to `:source`. We use `val=?`, where `?`
255262is the sign of type boolean (similar to `*`, `@`), which defaults to true (that
256263is, `0`).
257264
@@ -260,13 +267,13 @@ available (`val` is true). If so, we produce the move to subscribe to
260267`:source`:
261268
262269```
263− :~ :* ost.bow
264− %peer
265− /subscribe
266− [our.bow %source]
267− /example-path
268− ==
270+:~ :* ost.bow
271+ %peer
272+ /subscribe
273+ [our.bow %source]
274+ /example-path
269275 ==
276+==
270277```
271278
272279Also, in the preceding lines, we set `val` to false (`|`) with `+>.$(val |)`.
@@ -281,8 +288,8 @@ is false), then we unsubscribe from `:source` and set `val` back to true (`&`),
281288again using our handy inverted cell constructor mold `:_`:
282289
283290```
284− :_ +>.$(val &)
285− ~[[ost.bow %pull /subscribe [our.bow %source] ~]]
291+:_ +>.$(val &)
292+~[[ost.bow %pull /subscribe [our.bow %source] ~]]
286293```
287294
288295It's important to send over the same bone and wire (`/subscribe`) as the
@@ -293,10 +300,10 @@ state, based on whether `val` is true or false, and return a cell containing
293300a null list of moves and our unchanged app state:
294301
295302```
296− ~& ?: val
297− sink+unsubscribed+'You are now unsubscribed!'
298− sink+subscribed+'You are now subscribed!'
299− [~ +>.$]
303+~& ?: val
304+ sink+unsubscribed+'You are now unsubscribed!'
305+ sink+subscribed+'You are now subscribed!'
306+[~ +>.$]
300307```
301308
302309`++diff-noun` is called when we get a `%diff` update along a subscription with a
@@ -305,8 +312,8 @@ the `%peer` subscription request along and the data we got back. In our case we
305312just print out the data:
306313
307314```
308− ~& sink+received-data+'You got something!'
309− ~& sink+data+non
315+~& sink+received-data+'You got something!'
316+~& sink+data+non
310317```
311318
312319`++reap` is called when we receive an acknowledgment as to whether the