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