on 6d45ede help sign in
459 lines 9.5 kB history raw
1---
2navhome: /docs
3---
6# 4n: virtualization
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 `~`.
15Accepts
16-------
18`sub` is a subject noun.
20`fol` is a formula noun, which is generally a `++nock`.
22Produces
23--------
25The `++unit` of a noun.
27Source
28------
30 ++ mack
31 |= {sub/* fol/*}
32 ^- (unit)
33 =+ ton=(mink [sub fol] |=({* *} ~))
34 ?.(?=({$0 *} ton) ~ [~ p.ton])
35 ::
38Examples
39--------
41 > (mack [[1 2 3] [0 1]])
42 [~ [1 2 3]]
43 > (mack [41 4 0 1])
44 [~ 42]
45 > (mack [4 0 4])
46 ~
47 > (mack [[[0 2] [1 3]] 4 4 4 4 0 5])
48 [~ 6]
49 > ;;((unit @tas) (mack [[1 %yes %no] 6 [0 2] [0 6] 0 7]))
50 [~ %no]
54***
55### `++mink`
57Mock interpreter
59Bottom-level mock (virtual nock) interpreter. Produces a
60`++tone`, a nock computation result. If nock 11 is invoked, `sky`
61computes on the subject and produces a `++unit` result. An empty
62result becomes a `%1` `++tone`, indicating a block.
64Accepts
65-------
67`sub` is the subject as a noun.
69`fol` is the formula as a noun.
71`sky` is an `%iron` gate invoked with nock operator 11.
73Produces
74--------
76A `++tone`.
78Source
79------
81 ++ mink
82 ~/ %mink
83 |= {{sub/* fol/*} gul/$-({* *} (unit (unit)))}
84 =+ tax=*(list {@ta *})
85 |- ^- tone
86 ?@ fol
87 [%2 tax]
88 ?: ?=(^ -.fol)
89 =+ hed=$(fol -.fol)
90 ?: ?=($2 -.hed)
91 hed
92 =+ tal=$(fol +.fol)
93 ?- -.tal
94 $0 ?-(-.hed $0 [%0 p.hed p.tal], $1 hed)
95 $1 ?-(-.hed $0 tal, $1 [%1 (weld p.hed p.tal)])
96 $2 tal
97 ==
98 ?+ fol
99 [%2 tax]
100 ::
101 {$0 b/@}
102 ?: =(0 b.fol) [%2 tax]
103 ?: =(1 b.fol) [%0 sub]
104 ?: ?=(@ sub) [%2 tax]
105 =+ [now=(cap b.fol) lat=(mas b.fol)]
106 $(b.fol lat, sub ?:(=(2 now) -.sub +.sub))
107 ::
108 {$1 b/*}
109 [%0 b.fol]
110 ::
111 {$2 b/{^ *}}
112 =+ ben=$(fol b.fol)
113 ?. ?=($0 -.ben) ben
114 ?>(?=(^ p.ben) $(sub -.p.ben, fol +.p.ben))
115 ::?>(?=(^ p.ben) $([sub fol] p.ben)
116 ::
117 {$3 b/*}
118 =+ ben=$(fol b.fol)
119 ?. ?=($0 -.ben) ben
120 [%0 .?(p.ben)]
121 ::
122 {$4 b/*}
123 =+ ben=$(fol b.fol)
124 ?. ?=($0 -.ben) ben
125 ?. ?=(@ p.ben) [%2 tax]
126 [%0 .+(p.ben)]
127 ::
128 {$5 b/*}
129 =+ ben=$(fol b.fol)
130 ?. ?=($0 -.ben) ben
131 ?. ?=(^ p.ben) [%2 tax]
132 [%0 =(-.p.ben +.p.ben)]
133 ::
134 {$6 b/* c/* d/*}
135 $(fol =>(fol [2 [0 1] 2 [1 c d] [1 0] 2 [1 2 3] [1 0] 4 4 b]))
136 ::
137 {$7 b/* c/*} $(fol =>(fol [2 b 1 c]))
138 {$8 b/* c/*} $(fol =>(fol [7 [[0 1] b] c]))
139 {$9 b/* c/*} $(fol =>(fol [7 c 0 b]))
140 {$10 @ c/*} $(fol c.fol)
141 {$10 {b/* c/*} d/*}
142 =+ ben=$(fol c.fol)
143 ?. ?=($0 -.ben) ben
144 ?: ?=(?($hunk $hand $lose $mean $spot) b.fol)
145 $(fol d.fol, tax [[b.fol p.ben] tax])
146 $(fol d.fol)
147 ::
148 {$11 b/* c/*}
149 =+ ref=$(fol b.fol)
150 =+ ben=$(fol c.fol)
151 ?. ?=($0 -.ref) ref
152 ?. ?=($0 -.ben) ben
153 =+ val=(gul p.ref p.ben)
154 ?~(val [%1 p.ben ~] ?~(u.val [%2 [[%hunk (mush p.ben)] tax]] [%0 u.u.val]))
155 ==
156 ::
159Examples
160--------
162 > (mink [20 [4 0 1]] $~)
163 [%0 p=21]
164 > (mink [[90 5 3] [0 3]] $~)
165 [%0 p=[5 3]]
166 > (mink 20^[4 0 1] $~)
167 [%0 p=21]
168 > (mink [90 5 3]^[0 3] $~)
169 [%0 p=[5 3]]
170 > (mink [0]^[11 1 20] $~)
171 [%1 p=~[20]]
172 > (mink [0]^[11 1 20] |=(a=* `[40 a]))
173 [%0 p=[40 20]]
174 > (mink [5]^[0 2] $~)
175 [%2 p=~]
176 > (mink [5]^[10 yelp/[0 1] 0 0] $~)
177 [%2 p=~[[~.yelp 5]]]
180***
181### `++mock`
183Compute formula on subject with hint
185Produces a `++toon`, which is either a sucessful, blocked, or
186crashed result. If nock 11 is invoked, `sky` computes on the subject and
187produces a `++unit` result. An empty result becomes a `%1` `++tune`,
188indicating a block.
190Accepts
191-------
193`sub` is the subject as a noun.
195`fol` is the formula as a noun.
197`sky` is an %iron gate invoked with nock operator 11.
199Produces
200--------
202The `++unit` of a noun.
204Source
205------
207 ++ mock
208 |= {{sub/* fol/*} gul/$-({* *} (unit (unit)))}
209 (mook (mink [sub fol] gul))
210 ::
213Examples
214--------
216 > (mock [5 4 0 1] ,~)
217 [%0 p=6]
218 > (mock [~ 11 1 0] |=(* `999))
219 [%0 p=999]
220 > (mock [~ 0 1.337] ,~)
221 [%2 p=~]
222 > (mock [~ 11 1 1.337] ,~)
223 [%1 p=~[1.337]]
224 > (mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[+<]))
225 [%0 p=14]
226 > (mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[<+<>]))
227 [%0 p=[49 52 0]]
228 > ;;(tape +:(mock [[[4 4 4 4 0 3] 10] 11 9 2 0 1] |=(* `[<+<>])))
229 "14"
233***
234### `++mong`
236Slam gate with sample
238Produces a `++toon` computation result from slamming `gat` with
239`sam`, using `sky` to compute or block on nock 11 when applicable.
241Accepts
242-------
244`gat` is a noun that is generally a `gate`.
246`sam` is a `sample` noun.
248`sky` is an %iron gate invoked with nock operator 11.
250Produces
251--------
253A `++toon`.
255Source
256------
258 ++ mong
259 |= {{gat/* sam/*} gul/$-({* *} (unit (unit)))}
260 ^- toon
261 ?. &(?=(^ gat) ?=(^ +.gat))
262 [%2 ~]
263 (mock [[-.gat [sam +>.gat]] -.gat] gul)
264 ::
266Examples
267--------
269 > (mong [|=(@ 20) ~] ,~)
270 [%0 p=20]
271 > (mong [|=(@ !!) ~] ,~)
272 [%2 p=~]
273 > (mong [|=(a/@ (add 20 a)) ~] ,~)
274 [%0 p=20]
275 > (mong [|=(a/[@ @] (add 20 -.a)) ~] ,~)
276 [%2 p=~]
277 > (mong [|=(a/[@ @] (add 20 -.a)) [4 6]] ,~)
278 [%0 p=24]
279 > (mong [|=(a/@ .^(a)) ~] ,~)
280 [%1 p=~[0]]
281 > (mong [|=(a/@ .^(a)) ~] ,[~ %42])
282 [%0 p=42]
283 > (mong [|=(a/@ .^(a)) ~] |=(a/* [~ a 6]))
284 [%0 p=[0 6]]
285 > (mong [|=(a/@ .^(a)) 8] |=(a/* [~ a 6]))
286 [%0 p=[8 6]]
290***
291### `++mook`
293Intelligently render crash annotation
295Converts a `%2` `++tone` nock stack trace to a list of `++tank`.
296Each may be a tank, cord, `++spot`, or trapped tank.
298Accepts
299-------
301`ton` is a `++tone`.
303Produces
304--------
306A `++toon`.
308Source
309------
311 ++ mook
312 |= ton/tone
313 ^- toon
314 ?. ?=({$2 *} ton) ton
315 :- %2
316 :: =. p.ton (moop p.ton)
317 =+ yel=(lent p.ton)
318 =. p.ton
319 ?. (gth yel 256) p.ton
320 %+ weld
321 (scag 128 p.ton)
322 ^- (list {@ta *})
323 :_ (slag (sub yel 128) p.ton)
324 :- %lose
325 %+ rap 3
326 "[skipped {(scow %ud (sub yel 256))} frames]"
327 |- ^- (list tank)
328 ?~ p.ton ~
329 =+ rep=$(p.ton t.p.ton)
330 ?+ -.i.p.ton rep
331 $hunk [(tank +.i.p.ton) rep]
332 $lose [[%leaf (rip 3 (@ +.i.p.ton))] rep]
333 $hand [[%leaf (scow %p (mug +.i.p.ton))] rep]
334 $mean :_ rep
335 ?@ +.i.p.ton [%leaf (rip 3 (@ +.i.p.ton))]
336 =+ mac=(mack +.i.p.ton +<.i.p.ton)
337 ?~(mac [%leaf "####"] (tank u.mac))
338 $spot :_ rep
339 =+ sot=(spot +.i.p.ton)
340 :+ %rose [":" ~ ~]
341 :~ (smyt p.sot)
342 => [ud=|=(a/@u (scow %ud a)) q.sot]
343 leaf+"<[{(ud p.p)} {(ud q.p)}].[{(ud p.q)} {(ud q.q)}]>"
344 == ==
345 ::
347Examples
348--------
350 > (mook [%0 5 4 5 1])
351 [%0 p=[5 4 5 1]]
352 > (mook [%2 ~[[%hunk %rose ["<" "," ">"] ~[[%leaf "err"]]]]])
353 [%2 p=~[[%rose p=[p="<" q="," r=">"] q=[i=[%leaf p="err"] t=~]]]]
354 > (mook [%2 ~[[%malformed %elem] [%lose 'do print']]])
355 [%2 p=~[[%leaf p="do print"]]]
356 > (mook [%2 ~[[%mean |.(>(add 5 6)<)]]])
357 [%2 p=~[[%leaf p="11"]]]
358 > (mook [%2 ~[[%spot /b/repl [1 1]^[1 2]] [%mean |.(!!)]]])
359 [%2 p=~[[%leaf p="/b/repl/:<[1 1].[1 2]>"] [%leaf p="####"]]]
363***
364### `++mule`
366Typed virtual
368Kicks a `++trap`, producing its results or any errors that occur along
369the way. Used to lazily compute stack traces.
371Accepts
372-------
374`taq` is a `++trap`, generally producing a list of `++tank`s.
376Produces
377--------
379XX
381Source
382------
384 ++ mule :: typed virtual
385 ~/ %mule
386 |* taq/_|.(**)
387 =+ mud=(mute taq)
388 ?- -.mud
389 $& [%& p=$:taq] :: XX transition
390 $| [%| p=p.mud]
391 ==
392 ::
395Examples
396--------
398 > (mule |.(leaf/"hello"))
399 [%.y p=[%leaf "hello"]]
400 > (mule |.(!!))
401 [%.n p=~]
402 > (mule |.(.^(a//=pals/1)))
403 [ %.n
404 p
405 ~[
406 [ %rose
407 p=[p="/" q="/" r="/"]
408 q
409 [ i=[%leaf p="a"]
410 t=[i=[%leaf p="~zod"] t=[i=[%leaf p="pals"] t=[i=[%leaf p="1"] t=~]]]
411 ]
412 ]
413 ]
414 ]
418***
419### `++mute`
421Untyped virtual
423Kicks a `++trap`, producing its result as a noun or the tanks of any
424error that occurs. Similar to `++mule`, but preserves no type
425information.
427Accepts
428-------
430`taq` is a `++trap`.
431Produces
432--------
434Either a noun or a `++list` of `++tank`.
436Source
437------
439 ++ mute :: untyped virtual
440 |= taq/_^?(|.(**))
441 ^- (each * (list tank))
442 =+ ton=(mock [taq 9 2 0 1] |=({* *} ~))
443 ?- -.ton
444 $0 [%& p.ton]
445 $1 [%| (turn p.ton |=(a/* (smyt (path a))))]
446 $2 [%| p.ton]
447 ==
450Examples
451--------
453 > (mute |.(leaf/"hello"))
454 [%.y p=[1.717.658.988 104 101 108 108 111 0]]
455 > (mute |.(!!))
456 [%.n p=~]
459***