on 4fdc19d help sign in
355 lines 5.8 kB history raw
1+++
2title = "3g: Molds and Mold-Builders"
3weight = 27
4template = "doc.html"
5+++
7## `+$coin`
9Noun-literal syntax cases
11Syntax cases for nouns-literal: atoms, jammed nouns, and nestable tuples. Parsed
12and printed using `++so` and `++co` cores.
14#### Source
16```hoon
17+$ coin $~ [%$ %ud 0]
18 $% [%$ p=dime]
19 [%blob p=*]
20 [%many p=(list coin)]
21```
23#### Examples
25```
26> `coin`(need (slay '~s1'))
27[%$ p=[p=~.dr q=18.446.744.073.709.551.616]]
29> `coin`(need (slay '0x2b59'))
30[%$ p=[p=~.ux q=11.097]]
32> ~(rend co [%many ~[[%$ %ud 1] [%$ %tas 'a'] [%$ %s -2]]])
33"._1_a_-2__"
34> ._1_a_-2__
35[1 %a -2]
37> `@uv`(jam [3 4])
380v2cd1
40> (slay '~02cd1')
41[~ u=[%blob p=[3 4]]]
43> ~02cd1
44[3 4]
45```
47---
49## `+$dime`
51Aura-atom pair
53Used in `++coin`. Convenience methods
54[`++scot`](/docs/hoon/reference/stdlib/4m#scot) and
55[`++scow`](/docs/hoon/reference/stdlib/4m#scow) print dimes as `++cord` and
56`++tape`, respectively. [`++slat`](/docs/hoon/reference/stdlib/4m#slat),
57[`++slav`](/docs/hoon/reference/stdlib/4m#slav), and
58[`++slaw`](/docs/hoon/reference/stdlib/4m#slaw) are used to parse atoms of
59specific auras.
61#### Source
63```hoon
64+$ dime [p=@ta q=@]
65```
67#### Examples
69```
70> +>:(slay '0x123')
71p=[p=~.ux q=291]
72```
74---
76## `+$edge`
78Parsing location metadata. Parsing location input `p` and optional result `p.q` and parsing continuation `q.q`.
80#### Source
82```hoon
83+$ edge [p=hair q=(unit [p=* q=nail])]
84```
86#### Examples
88```
89> *edge
90[p=[p=0 q=0] q=~]
92> (tall:vast [1 1] "a b")
93[p=[p=1 q=3] q=[~ u=[p=[%wing p=~[%a]] q=[p=[p=1 q=2] q=" b"]]]]
94```
96#### Discussion
98See also: [$rule](#rule).
100---
102## `+$hair`
104Parsing line and column
106A pair of two `@ud` used in parsing indicating line and column number.
108#### Source
110```hoon
111+$ hair [p=@ud q=@ud]
112```
114#### Examples
116```
117> *hair
118[p=0 q=0]
120> `hair`[1 1] :: parsing starts at [1 1] as a convention.
121[p=1 q=1]
123> ((plus ace) [1 1] " --")
124[p=[p=1 q=4] q=[~ u=[p=[~~. " "] q=[p=[p=1 q=4] q="--"]]]]
126> `hair`p:((plus ace) [1 1] " --")
127[p=1 q=4]
128```
130---
132## `++like`
134Generic edge
136Generates an [`$edge`](#edge) with a parsed result set to a specific type.
138#### Source
140```hoon
141++ like |* a=$-(* *)
142 |: b=`*`[(hair) ~]
143 :- p=(hair -.b)
144 ^= q
145 ?@ +.b ~
146 :- ~
147 u=[p=(a +>-.b) q=[p=(hair -.b) q=(tape +.b)]]
148```
150#### Examples
152```
153> *(like char)
154[p=[p=0 q=0] q=~]
156> (ace [1 1] " a")
157[p=[p=1 q=2] q=[~ u=[p=' ' q=[p=[p=1 q=2] q="a"]]]]
159> `(like char)`(ace [1 1] " a")
160[p=[p=1 q=2] q=[~ [p=~~. q=[p=[p=1 q=2] q="a"]]]]
162> `(like ,@)`(ace [1 1] " a")
163[p=[p=1 q=2] q=[~ u=[p=32 q=[p=[p=1 q=2] q="a"]]]]
164```
166---
168## `+$nail`
170Location, remainder of parsed text
172Indicates parsing position `p`, and remaining text to be parsed `q`.
174#### Source
176```hoon
177+$ nail [p=hair q=tape]
178```
180#### Examples
182```
183> +<:;~(plug cab cab)
184c=[p=[p=0 q=0] q=""]
185```
187---
189## `+$pint`
191Parsing range
193A `$pint` is a pair of [`$hair`](#hair), indicating from `p` to `q`. Mostly used for
194stack traces.
196#### Source
198```hoon
199+$ pint [p=[p=@ q=@] q=[p=@ q=@]]
200```
202#### Examples
204```
205> !:(!!) :: !! always produces a crash
206/~zod/base/~2014.9.20..01.22.04..52e3/:<[1 4].[1 6]>
208> `pint`[[1 4] [1 6]]
209[p=[p=1 q=4] q=[p=1 q=6]]
210```
212---
214## `+$rule`
216Parsing rule
218An empty parsing rule, but used to check that parsing rules match this with `_`.
220#### Source
222```hoon
223+$ rule _|:($:nail $:edge)
224```
226#### Examples
228```
229> ([|=(a=nail [p.a ~ u=['a' a]])]:|6 [1 1] "hi")
230[[p=1 q=1] ~ u=['a' p=[p=1 q=1] q="hi"]]
231```
233---
235## `+$spot`
237Stack trace line
239The stack trace that is printed after crashing.
241#### Source
243```hoon
244 ++ spot [p=path q=pint]
245```
247#### Examples
249```
250> !: !! :: !! always produces a crash
251/~zod/base/~2018.8.8..21.42.40..7852:<[1 5].[1 7]>
252! exit
253```
255---
257## `+$tone`
259Nock result, error report
261Produces either success (`%0`), a block with list of requests blocked on (`%1`),
262or failure with an error report (`%2`).
264#### Source
266```hoon
267+$ tone $% [%0 product=*]
268 [%1 block=*]
269 [%2 trace=(list [@ta *])]
270 ==
271```
273#### Examples
275```
276> (mink [[20 21] 0 3] $~)
277[%0 product=21]
278```
280```
281> (mink [[1 2] !=(!:(+(.)))] ,~)
282[%2 trace=~[[~.spot [[1.685.027.454 1.702.060.386 20.241.306.789.072.368.304.935.424.358.627.395.315.601.229.215.400.789.787.861.332.606 0] [1 20] 1 24]]]]
283```
285---
287## `+$toon`
289Nock result, stack trace
291Produces either success (`%0`), a block with list of requests blocked on (`%1`),
292or failure with a stack trace (`%2`).
294#### Source
296```hoon
297+$ toon $% [%0 p=*] :: success
298 [%1 p=*] :: block
299 [%2 p=(list tank)] :: stack trace
300 == ::
301```
303#### Examples
305```
306> (mock [[20 21] 0 3] $~)
307[%0 p=21]
308```
310```
311> (mock [[1 2] !=(!:(+(.)))] ,~)
312[ %2
313 p
314 ~[
315 [ %rose
316 p=[p=":" q="" r=""]
317 q=[i=[%rose p=[p="/" q="/" r=""] q=[i=[%leaf p="~zod"] t=[i=[%leaf p="base"] t=[i=[%leaf p="~2021.10.16..10.03.16..59ee"] t=~]]]] t=[i=[%leaf p="<[1 20].[1 24]>"] t=~]]
318 ]
319 ]
321```
323---
325## `++wonk`
327Product from edge
329Pull result out of a [`$edge`](#edge), or crash if there's no result.
331#### Source
333```hoon
334++ wonk =+ veq=$:edge
335 |@ ++ $ ?~(q.veq !! p.u.q.veq)
336 --
337```
339#### Examples
341```
342> (wide:vast [1 1] "(add 2 2)")
343[p=[p=1 q=10] q=[~ [p=[%cncl p=[%wing p=~[%add]] q=~[[%sand p=%ud q=2] [%sand p=%ud q=2]]] q=[p=[p=1 q=10] q=""]]]]
344```
346```
347> (wonk (wide:vast [1 1] "(add 2 2)"))
348[%cncl p=[%wing p=~[%add]] q=~[[%sand p=%ud q=2] [%sand p=%ud q=2]]]
349```
351#### Discussion
353See also: [`$edge`](#edge)
355---