on b00decd help sign in
447 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```
52---
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---
177### `++mock`
179Compute formula on subject with hint
181Produces a `++toon`, which is either a sucessful, blocked, or
182crashed result. If nock 11 is invoked, `sky` computes on the subject and
183produces a `++unit` result. An empty result becomes a `%1` `++tune`,
184indicating a block.
186#### Accepts
188`sub` is the subject as a noun.
190`fol` is the formula as a noun.
192`sky` is an %iron gate invoked with nock operator 11.
194#### Produces
196The `++unit` of a noun.
198#### Source
200```hoon
201 ++ mock
202 |= {{sub/* fol/*} gul/$-({* *} (unit (unit)))}
203 (mook (mink [sub fol] gul))
204 ::
205```
207#### Examples
209```
210 > (mock [5 4 0 1] ,~)
211 [%0 p=6]
212 > (mock [~ 11 1 0] |=(* `999))
213 [%0 p=999]
214 > (mock [~ 0 1.337] ,~)
215 [%2 p=~]
216 > (mock [~ 11 1 1.337] ,~)
217 [%1 p=~[1.337]]
218 > (mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[+<]))
219 [%0 p=14]
220 > (mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[<+<>]))
221 [%0 p=[49 52 0]]
222 > ;;(tape +:(mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[<+<>])))
223 "14"
224```
227---
228### `++mong`
230Slam gate with sample
232Produces a `++toon` computation result from slamming `gat` with
233`sam`, using `sky` to compute or block on nock 11 when applicable.
235#### Accepts
237`gat` is a noun that is generally a `gate`.
239`sam` is a `sample` noun.
241`sky` is an %iron gate invoked with nock operator 11.
243#### Produces
245A `++toon`.
247#### Source
249```hoon
250 ++ mong
251 |= {{gat/* sam/*} gul/$-({* *} (unit (unit)))}
252 ^- toon
253 ?. &(?=(^ gat) ?=(^ +.gat))
254 [%2 ~]
255 (mock [[-.gat [sam +>.gat]] -.gat] gul)
256 ::
257```
259#### Examples
261```
262 > (mong [|=(@ 20) ~] ,~)
263 [%0 p=20]
264 > (mong [|=(@ !!) ~] ,~)
265 [%2 p=~]
266 > (mong [|=(a/@ (add 20 a)) ~] ,~)
267 [%0 p=20]
268 > (mong [|=(a/[@ @] (add 20 -.a)) ~] ,~)
269 [%2 p=~]
270 > (mong [|=(a/[@ @] (add 20 -.a)) [4 6]] ,~)
271 [%0 p=24]
272 > (mong [|=(a/@ .^(a)) ~] ,~)
273 [%1 p=~[0]]
274 > (mong [|=(a/@ .^(a)) ~] ,[~ %42])
275 [%0 p=42]
276 > (mong [|=(a/@ .^(a)) ~] |=(a/* [~ a 6]))
277 [%0 p=[0 6]]
278 > (mong [|=(a/@ .^(a)) 8] |=(a/* [~ a 6]))
279 [%0 p=[8 6]]
280```
283---
284### `++mook`
286Intelligently render crash annotation
288Converts a `%2` `++tone` nock stack trace to a list of `++tank`.
289Each may be a tank, cord, `++spot`, or trapped tank.
291#### Accepts
293`ton` is a `++tone`.
295#### Produces
297A `++toon`.
299#### Source
301```hoon
302 ++ mook
303 |= ton/tone
304 ^- toon
305 ?. ?=({$2 *} ton) ton
306 :- %2
307 :: =. p.ton (moop p.ton)
308 =+ yel=(lent p.ton)
309 =. p.ton
310 ?. (gth yel 256) p.ton
311 %+ weld
312 (scag 128 p.ton)
313 ^- (list {@ta *})
314 :_ (slag (sub yel 128) p.ton)
315 :- %lose
316 %+ rap 3
317 "[skipped {(scow %ud (sub yel 256))} frames]"
318 |- ^- (list tank)
319 ?~ p.ton ~
320 =+ rep=$(p.ton t.p.ton)
321 ?+ -.i.p.ton rep
322 $hunk [(tank +.i.p.ton) rep]
323 $lose [[%leaf (rip 3 (@ +.i.p.ton))] rep]
324 $hand [[%leaf (scow %p (mug +.i.p.ton))] rep]
325 $mean :_ rep
326 ?@ +.i.p.ton [%leaf (rip 3 (@ +.i.p.ton))]
327 =+ mac=(mack +.i.p.ton +<.i.p.ton)
328 ?~(mac [%leaf "####"] (tank u.mac))
329 $spot :_ rep
330 =+ sot=(spot +.i.p.ton)
331 :+ %rose [":" ~ ~]
332 :~ (smyt p.sot)
333 => [ud=|=(a/@u (scow %ud a)) q.sot]
334 leaf+"<[{(ud p.p)} {(ud q.p)}].[{(ud p.q)} {(ud q.q)}]>"
335 == ==
336 ::
337```
339#### Examples
341```
342 > (mook [%0 5 4 5 1])
343 [%0 p=[5 4 5 1]]
344 > (mook [%2 ~[[%hunk %rose ["<" "," ">"] ~[[%leaf "err"]]]]])
345 [%2 p=~[[%rose p=[p="<" q="," r=">"] q=[i=[%leaf p="err"] t=~]]]]
346 > (mook [%2 ~[[%malformed %elem] [%lose 'do print']]])
347 [%2 p=~[[%leaf p="do print"]]]
348 > (mook [%2 ~[[%mean |.(>(add 5 6)<)]]])
349 [%2 p=~[[%leaf p="11"]]]
350 > (mook [%2 ~[[%spot /b/repl [1 1]^[1 2]] [%mean |.(!!)]]])
351 [%2 p=~[[%leaf p="/b/repl/:<[1 1].[1 2]>"] [%leaf p="####"]]]
352```
355---
356### `++mule`
358Typed virtual
360Kicks a `++trap`, producing its results or any errors that occur along
361the way. Used to lazily compute stack traces.
363#### Accepts
365`taq` is a `++trap`, generally producing a list of `++tank`s.
367#### Produces
369XX
371#### Source
373```hoon
374 ++ mule :: typed virtual
375 ~/ %mule
376 |* taq/_|.(**)
377 =+ mud=(mute taq)
378 ?- -.mud
379 $& [%& p=$:taq] :: XX transition
380 $| [%| p=p.mud]
381 ==
382 ::
383```
385#### Examples
387```
388 > (mule |.(leaf/"hello"))
389 [%.y p=[%leaf "hello"]]
390 > (mule |.(!!))
391 [%.n p=~]
392 > (mule |.(.^(a//=pals/1)))
393 [ %.n
394 p
395 ~[
396 [ %rose
397 p=[p="/" q="/" r="/"]
398 q
399 [ i=[%leaf p="a"]
400 t=[i=[%leaf p="~zod"] t=[i=[%leaf p="pals"] t=[i=[%leaf p="1"] t=~]]]
401 ]
402 ]
403 ]
404 ]
405```
408---
409### `++mute`
411Untyped virtual
413Kicks a `++trap`, producing its result as a noun or the tanks of any
414error that occurs. Similar to `++mule`, but preserves no type
415information.
417#### Accepts
419`taq` is a `++trap`.
420#### Produces
422Either a noun or a `++list` of `++tank`.
424#### Source
426```hoon
427 ++ mute :: untyped virtual
428 |= taq/_^?(|.(**))
429 ^- (each * (list tank))
430 =+ ton=(mock [taq 9 2 0 1] |=({* *} ~))
431 ?- -.ton
432 $0 [%& p.ton]
433 $1 [%| (turn p.ton |=(a/* (smyt (path a))))]
434 $2 [%| p.ton]
435 ==
436```
438#### Examples
440```
441 > (mute |.(leaf/"hello"))
442 [%.y p=[1.717.658.988 104 101 108 108 111 0]]
443 > (mute |.(!!))
444 [%.n p=~]
445```
447---