on bbd4189 help sign in
449 lines 9.6 kB history raw
1+++
2title = "4n: Virtualization"
3weight = 41
4template = "doc.html"
5+++
7## `++mack`
9Nock subject to unit
11Accepts a nock subject-formula cell and wraps it into a `++unit`.
12`fol` is pure nock, meaning that nock `11` operations result in a block,
13producing a `~`.
15#### Accepts
17`sub` is a subject noun.
19`fol` is a formula noun, which is generally a `++nock`.
21#### Produces
23The `++unit` of a noun.
25#### Source
27```hoon
28 ++ mack
29 |= {sub/* fol/*}
30 ^- (unit)
31 =+ ton=(mink [sub fol] |=({* *} ~))
32 ?.(?=({$0 *} ton) ~ [~ p.ton])
33 ::
34```
36#### Examples
38```
39 > (mack [[1 2 3] [0 1]])
40 [~ [1 2 3]]
41 > (mack [41 4 0 1])
42 [~ 42]
43 > (mack [4 0 4])
44 ~
45 > (mack [[[0 2] [1 3]] 4 4 4 4 0 5])
46 [~ 6]
47 > ;;((unit @tas) (mack [[1 %yes %no] 6 [0 2] [0 6] 0 7]))
48 [~ %no]
49```
51---
53## `++mink`
55Mock interpreter
57Bottom-level mock (virtual nock) interpreter. Produces a
58`++tone`, a nock computation result. If nock 11 is invoked, `sky`
59computes on the subject and produces a `++unit` result. An empty
60result becomes a `%1` `++tone`, indicating a block.
62#### Accepts
64`sub` is the subject as a noun.
66`fol` is the formula as a noun.
68`sky` is an `%iron` gate invoked with nock operator 11.
70#### Produces
72A `++tone`.
74#### Source
76```hoon
77 ++ mink
78 ~/ %mink
79 |= {{sub/* fol/*} gul/$-({* *} (unit (unit)))}
80 =+ tax=*(list {@ta *})
81 |- ^- tone
82 ?@ fol
83 [%2 tax]
84 ?: ?=(^ -.fol)
85 =+ hed=$(fol -.fol)
86 ?: ?=($2 -.hed)
87 hed
88 =+ tal=$(fol +.fol)
89 ?- -.tal
90 $0 ?-(-.hed $0 [%0 p.hed p.tal], $1 hed)
91 $1 ?-(-.hed $0 tal, $1 [%1 (weld p.hed p.tal)])
92 $2 tal
93 ==
94 ?+ fol
95 [%2 tax]
96 ::
97 {$0 b/@}
98 ?: =(0 b.fol) [%2 tax]
99 ?: =(1 b.fol) [%0 sub]
100 ?: ?=(@ sub) [%2 tax]
101 =+ [now=(cap b.fol) lat=(mas b.fol)]
102 $(b.fol lat, sub ?:(=(2 now) -.sub +.sub))
103 ::
104 {$1 b/*}
105 [%0 b.fol]
106 ::
107 {$2 b/{^ *}}
108 =+ ben=$(fol b.fol)
109 ?. ?=($0 -.ben) ben
110 ?>(?=(^ p.ben) $(sub -.p.ben, fol +.p.ben))
111 ::?>(?=(^ p.ben) $([sub fol] p.ben)
112 ::
113 {$3 b/*}
114 =+ ben=$(fol b.fol)
115 ?. ?=($0 -.ben) ben
116 [%0 .?(p.ben)]
117 ::
118 {$4 b/*}
119 =+ ben=$(fol b.fol)
120 ?. ?=($0 -.ben) ben
121 ?. ?=(@ p.ben) [%2 tax]
122 [%0 .+(p.ben)]
123 ::
124 {$5 b/*}
125 =+ ben=$(fol b.fol)
126 ?. ?=($0 -.ben) ben
127 ?. ?=(^ p.ben) [%2 tax]
128 [%0 =(-.p.ben +.p.ben)]
129 ::
130 {$6 b/* c/* d/*}
131 $(fol =>(fol [2 [0 1] 2 [1 c d] [1 0] 2 [1 2 3] [1 0] 4 4 b]))
132 ::
133 {$7 b/* c/*} $(fol =>(fol [2 b 1 c]))
134 {$8 b/* c/*} $(fol =>(fol [7 [[0 1] b] c]))
135 {$9 b/* c/*} $(fol =>(fol [7 c 0 b]))
136 {$10 @ c/*} $(fol c.fol)
137 {$10 {b/* c/*} d/*}
138 =+ ben=$(fol c.fol)
139 ?. ?=($0 -.ben) ben
140 ?: ?=(?($hunk $hand $lose $mean $spot) b.fol)
141 $(fol d.fol, tax [[b.fol p.ben] tax])
142 $(fol d.fol)
143 ::
144 {$11 b/* c/*}
145 =+ ref=$(fol b.fol)
146 =+ ben=$(fol c.fol)
147 ?. ?=($0 -.ref) ref
148 ?. ?=($0 -.ben) ben
149 =+ val=(gul p.ref p.ben)
150 ?~(val [%1 p.ben ~] ?~(u.val [%2 [[%hunk (mush p.ben)] tax]] [%0 u.u.val]))
151 ==
152 ::
153```
155#### Examples
157```
158 > (mink [20 [4 0 1]] $~)
159 [%0 p=21]
160 > (mink [[90 5 3] [0 3]] $~)
161 [%0 p=[5 3]]
162 > (mink 20^[4 0 1] $~)
163 [%0 p=21]
164 > (mink [90 5 3]^[0 3] $~)
165 [%0 p=[5 3]]
166 > (mink [0]^[11 1 20] $~)
167 [%1 p=~[20]]
168 > (mink [0]^[11 1 20] |=(a=* `[40 a]))
169 [%0 p=[40 20]]
170 > (mink [5]^[0 2] $~)
171 [%2 p=~]
172 > (mink [5]^[10 yelp/[0 1] 0 0] $~)
173 [%2 p=~[[~.yelp 5]]]
174```
176---
178## `++mock`
180Compute formula on subject with hint
182Produces a `++toon`, which is either a sucessful, blocked, or
183crashed result. If nock 11 is invoked, `sky` computes on the subject and
184produces a `++unit` result. An empty result becomes a `%1` `++tune`,
185indicating a block.
187#### Accepts
189`sub` is the subject as a noun.
191`fol` is the formula as a noun.
193`sky` is an %iron gate invoked with nock operator 11.
195#### Produces
197The `++unit` of a noun.
199#### Source
201```hoon
202 ++ mock
203 |= {{sub/* fol/*} gul/$-({* *} (unit (unit)))}
204 (mook (mink [sub fol] gul))
205 ::
206```
208#### Examples
210```
211 > (mock [5 4 0 1] ,~)
212 [%0 p=6]
213 > (mock [~ 11 1 0] |=(* `999))
214 [%0 p=999]
215 > (mock [~ 0 1.337] ,~)
216 [%2 p=~]
217 > (mock [~ 11 1 1.337] ,~)
218 [%1 p=~[1.337]]
219 > (mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[+<]))
220 [%0 p=14]
221 > (mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[<+<>]))
222 [%0 p=[49 52 0]]
223 > ;;(tape +:(mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[<+<>])))
224 "14"
225```
227---
229## `++mong`
231Slam gate with sample
233Produces a `++toon` computation result from slamming `gat` with
234`sam`, using `sky` to compute or block on nock 11 when applicable.
236#### Accepts
238`gat` is a noun that is generally a `gate`.
240`sam` is a `sample` noun.
242`sky` is an %iron gate invoked with nock operator 11.
244#### Produces
246A `++toon`.
248#### Source
250```hoon
251 ++ mong
252 |= {{gat/* sam/*} gul/$-({* *} (unit (unit)))}
253 ^- toon
254 ?. &(?=(^ gat) ?=(^ +.gat))
255 [%2 ~]
256 (mock [[-.gat [sam +>.gat]] -.gat] gul)
257 ::
258```
260#### Examples
262```
263 > (mong [|=(@ 20) ~] ,~)
264 [%0 p=20]
265 > (mong [|=(@ !!) ~] ,~)
266 [%2 p=~]
267 > (mong [|=(a/@ (add 20 a)) ~] ,~)
268 [%0 p=20]
269 > (mong [|=(a/[@ @] (add 20 -.a)) ~] ,~)
270 [%2 p=~]
271 > (mong [|=(a/[@ @] (add 20 -.a)) [4 6]] ,~)
272 [%0 p=24]
273 > (mong [|=(a/@ .^(a)) ~] ,~)
274 [%1 p=~[0]]
275 > (mong [|=(a/@ .^(a)) ~] ,[~ %42])
276 [%0 p=42]
277 > (mong [|=(a/@ .^(a)) ~] |=(a/* [~ a 6]))
278 [%0 p=[0 6]]
279 > (mong [|=(a/@ .^(a)) 8] |=(a/* [~ a 6]))
280 [%0 p=[8 6]]
281```
283---
285## `++mook`
287Intelligently render crash annotation
289Converts a `%2` `++tone` nock stack trace to a list of `++tank`.
290Each may be a tank, cord, `++spot`, or trapped tank.
292#### Accepts
294`ton` is a `++tone`.
296#### Produces
298A `++toon`.
300#### Source
302```hoon
303 ++ mook
304 |= ton/tone
305 ^- toon
306 ?. ?=({$2 *} ton) ton
307 :- %2
308 :: =. p.ton (moop p.ton)
309 =+ yel=(lent p.ton)
310 =. p.ton
311 ?. (gth yel 256) p.ton
312 %+ weld
313 (scag 128 p.ton)
314 ^- (list {@ta *})
315 :_ (slag (sub yel 128) p.ton)
316 :- %lose
317 %+ rap 3
318 "[skipped {(scow %ud (sub yel 256))} frames]"
319 |- ^- (list tank)
320 ?~ p.ton ~
321 =+ rep=$(p.ton t.p.ton)
322 ?+ -.i.p.ton rep
323 $hunk [(tank +.i.p.ton) rep]
324 $lose [[%leaf (rip 3 (@ +.i.p.ton))] rep]
325 $hand [[%leaf (scow %p (mug +.i.p.ton))] rep]
326 $mean :_ rep
327 ?@ +.i.p.ton [%leaf (rip 3 (@ +.i.p.ton))]
328 =+ mac=(mack +.i.p.ton +<.i.p.ton)
329 ?~(mac [%leaf "####"] (tank u.mac))
330 $spot :_ rep
331 =+ sot=(spot +.i.p.ton)
332 :+ %rose [":" ~ ~]
333 :~ (smyt p.sot)
334 => [ud=|=(a/@u (scow %ud a)) q.sot]
335 leaf+"<[{(ud p.p)} {(ud q.p)}].[{(ud p.q)} {(ud q.q)}]>"
336 == ==
337 ::
338```
340#### Examples
342```
343 > (mook [%0 5 4 5 1])
344 [%0 p=[5 4 5 1]]
345 > (mook [%2 ~[[%hunk %rose ["<" "," ">"] ~[[%leaf "err"]]]]])
346 [%2 p=~[[%rose p=[p="<" q="," r=">"] q=[i=[%leaf p="err"] t=~]]]]
347 > (mook [%2 ~[[%malformed %elem] [%lose 'do print']]])
348 [%2 p=~[[%leaf p="do print"]]]
349 > (mook [%2 ~[[%mean |.(>(add 5 6)<)]]])
350 [%2 p=~[[%leaf p="11"]]]
351 > (mook [%2 ~[[%spot /b/repl [1 1]^[1 2]] [%mean |.(!!)]]])
352 [%2 p=~[[%leaf p="/b/repl/:<[1 1].[1 2]>"] [%leaf p="####"]]]
353```
355---
357## `++mule`
359Typed virtual
361Kicks a `++trap`, producing its results or any errors that occur along
362the way. Used to lazily compute stack traces.
364#### Accepts
366`taq` is a `++trap`, generally producing a list of `++tank`s.
368#### Produces
370XX
372#### Source
374```hoon
375 ++ mule :: typed virtual
376 ~/ %mule
377 |* taq/_|.(**)
378 =+ mud=(mute taq)
379 ?- -.mud
380 $& [%& p=$:taq] :: XX transition
381 $| [%| p=p.mud]
382 ==
383 ::
384```
386#### Examples
388```
389 > (mule |.(leaf/"hello"))
390 [%.y p=[%leaf "hello"]]
391 > (mule |.(!!))
392 [%.n p=~]
393 > (mule |.(.^(a//=pals/1)))
394 [ %.n
395 p
396 ~[
397 [ %rose
398 p=[p="/" q="/" r="/"]
399 q
400 [ i=[%leaf p="a"]
401 t=[i=[%leaf p="~zod"] t=[i=[%leaf p="pals"] t=[i=[%leaf p="1"] t=~]]]
402 ]
403 ]
404 ]
405 ]
406```
408---
410## `++mute`
412Untyped virtual
414Kicks a `++trap`, producing its result as a noun or the tanks of any
415error that occurs. Similar to `++mule`, but preserves no type
416information.
418#### Accepts
420`taq` is a `++trap`.
422#### Produces
424Either a noun or a `++list` of `++tank`.
426#### Source
428```hoon
429 ++ mute :: untyped virtual
430 |= taq/_^?(|.(**))
431 ^- (each * (list tank))
432 =+ ton=(mock [taq 9 2 0 1] |=({* *} ~))
433 ?- -.ton
434 $0 [%& p.ton]
435 $1 [%| (turn p.ton |=(a/* (smyt (path a))))]
436 $2 [%| p.ton]
437 ==
438```
440#### Examples
442```
443 > (mute |.(leaf/"hello"))
444 [%.y p=[1.717.658.988 104 101 108 108 111 0]]
445 > (mute |.(!!))
446 [%.n p=~]
447```
449---