on bbd4189 help sign in
365 lines 6.6 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 $% [$$ p=dime]
18 [$blob p=*]
19 [$many p=(list coin)]
20 ==
21```
23---
25#### Examples
27```
28 > `coin`(need (slay '~s1'))
29 [%$ p=[p=~.dr q=18.446.744.073.709.551.616]]
31 > `coin`(need (slay '0x2b59'))
32 [%$ p=[p=~.ux q=11.097]]
34 > ~(rend co [%many ~[[%$ %ud 1] [%$ %tas 'a'] [%$ %s -2]]])
35 "._1_a_-2__"
36 > ._1_a_-2__
37 [1 %a -2]
39 > `@uv`(jam [3 4])
40 0v2cd1
42 > (slay '~02cd1')
43 [~ u=[%blob p=[3 4]]]
45 > ~02cd1
46 [3 4]
47```
49---
51## `++dime`
53Aura-atom pair
55Used in `++coin`. Convenience methods [`++scot`](/docs/hoon/reference/stdlib/4m) and
56[`++scow`](/docs/hoon/reference/stdlib/4m) print dimes as `++cord` and `++tape`, respectively.
57[`++slat`](/docs/hoon/reference/stdlib/4m), [`++slav`](/docs/hoon/reference/stdlib/4m), and [`++slaw`](/docs/hoon/reference/stdlib/4m) are used
58to parse atoms of specific auras.
60#### Source
62```hoon
63 ++ dime [p=@ta q=@]
64```
66#### Examples
68```
69 > +>:(slay '0x123')
70 p=[p=~.ux q=291]
71```
73---
75## `++edge`
77Parsing location metadata. Parsing location input `p` and optional result `p.q` and parsing continuation `q.q`.
79#### Source
81```hoon
82 ++ edge [p=hair q=(unit [p=* q=nail])] :: parsing output
83```
85#### Examples
87```
88 > *edge
89 [p=[p=0 q=0] q=~]
91 > (tall:vast [1 1] "a b")
92 [p=[p=1 q=3] q=[~ u=[p=[%wing p=~[%a]] q=[p=[p=1 q=2] q=" b"]]]]
93```
95#### Discussion
97See also: [Section 3g](/docs/hoon/reference/stdlib/3g#rule), `++rule`
99---
101## `++hair`
103Parsing line and column
105A pair of two `@ud` used in parsing indicating line and column number.
107#### Source
109```hoon
110 ++ hair [p=@ud q=@ud]
111```
113#### Examples
115```
116 > *hair
117 [p=0 q=0]
119 > `hair`[1 1] :: parsing starts at [1 1] as a convention.
120 [p=1 q=1]
122 > ((plus ace) [1 1] " --")
123 [p=[p=1 q=4] q=[~ u=[p=[~~. " "] q=[p=[p=1 q=4] q="--"]]]]
125 > `hair`p:((plus ace) [1 1] " --")
126 [p=1 q=4]
127```
129---
131## `++like`
133Generic edge
135Generates an `++edge` with a parsed result set to a specific type.
137#### Source
139```hoon
140 ++ like |* a=gate
141 |= b=_`*`[(hair) ~]
142 :- p=(hair -.b)
143 ^= q
144 :- ~
145 u=[p=(a +>-.b) q=[p=(hair -.b) q=(tape +.b)]]
146```
148#### Examples
150```
151 > *(like char)
152 [p=[p=0 q=0] q=~]
154 > (ace [1 1] " a")
155 [p=[p=1 q=2] q=[~ u=[p=' ' q=[p=[p=1 q=2] q="a"]]]]
157 > `(like char)`(ace [1 1] " a")
158 [p=[p=1 q=2] q=[~ [p=~~. q=[p=[p=1 q=2] q="a"]]]]
160 > `(like ,@)`(ace [1 1] " a")
161 [p=[p=1 q=2] q=[~ u=[p=32 q=[p=[p=1 q=2] q="a"]]]]
162```
164---
166## `++nail`
168Location, remainder of parsed text
170Indicates parsing position `p`, and remaining text to be parsed `q`.
172#### Source
174```hoon
175 ++ nail [p=hair q=tape]
176```
178#### Examples
180```
181 > +<:;~(plug cab cab)
182 c=[p=[p=0 q=0] q=""]
183```
185---
187## `++pint`
189Parsing range
191A `++pint` is a pair of `++hair`, indicating from `p` to `q`. Mostly used for
192stack traces.
194#### Source
196```hoon
197 ++ pint [p=[p=@ q=@] q=[p=@ q=@]]
198```
200#### Examples
202```
203 > !:(!!) :: !! always produces a crash
204 /~zod/home/~2014.9.20..01.22.04..52e3/:<[1 4].[1 6]>
206 > `pint`[[1 4] [1 6]]
207 [p=[p=1 q=4] q=[p=1 q=6]]
208```
210---
212## `++rule`
214Parsing rule
216An empty parsing rule, but used to check that parsing rules match this with `_`.
218#### Source
220```hoon
221 ++ rule _|=(nail *edge)
222```
224#### Examples
226```
227 > ([|=(a=nail [p.a ~ u=['a' a]])]:|6 [1 1] "hi")
228 [[p=1 q=1] ~ u=['a' p=[p=1 q=1] q="hi"]]
229```
231---
233## `++spot`
235Stack trace line
237The stack trace that is printed after crashing.
239#### Source
241```hoon
242 ++ spot [p=path q=pint]
243```
245#### Examples
247```
248 > !: !! :: !! always produces a crash
249 /~zod/home/~2018.8.8..21.42.40..7852:<[1 5].[1 7]>
250 ! exit
251```
253---
255## `++tone`
257Nock result, error report
259Produces either success (`%0`), a block with list of requests blocked on (`%1`),
260or failure with an error report (`%2`).
262#### Source
264```hoon
265 ++ tone $% [$0 p=*] :: success
266 [$1 p=(list)] :: blocks
267 [$2 p=(list [@ta *])] :: error report
268 ==
269```
271#### Examples
273```
274 > (mink [[20 21] 0 3] $~)
275 [%0 p=21]
278 > (mink [[1 2] !=(!:(+(.)))] ,~)
279 [ %2
280 p
281 ~[
282 [ ~.spot
283 [ [ \/72.245.008.048.359.254.300.063.028.130.093.488.830.539.186.242.06\/
284 3.318.457.928.725.368.447.417.075.673.617.723.940.025.940.705.343
285 .057.601.925.133.611.559.292.046.932.324.629.048.702
286 \/ \/
287 1.701.670.760
288 \/347.698.068.472.453.194.464.038.059.283.550.210.118.689.128.761.6\/
289 88.459.326.078
290 \/ \/
291 0
292 ]
293 [1 20]
294 1
295 24
296 ]
297 ]
298 ]
299```
301---
303## `++toon`
305Nock result, stack trace
307Produces either success (`%0`), a block with list of requests blocked on (`%1`),
308or failure with a stack trace (`%2`).
310#### Source
312```hoon
313 ++ toon $% [$0 p=*] :: success
314 [$1 p=(list)] :: blocks
315 [$2 p=(list tank)] :: stack trace
316 ==
317```
319#### Examples
321```
322 > (mock [[20 21] 0 3] $~)
323 [%0 p=21]
325 > (mock [[1 2] !=(!:(+(.)))] ,~)
326 [%2 p=~[[%leaf p="/~zod/try/~2014.9.23..18.34.32..d3c5/:<[1 20].[1 24]>"]]]
327```
329---
331## `++wonk`
333Product from edge
335Pull result out of a `++edge`, or crash if there's no result.
337#### Source
339```hoon
340 ++ wonk |*(veq=edge ?~(q.veq !! p.u.q.veq))
341```
343#### Examples
345```
346 > (wide:vast [1 1] "(add 2 2)")
347 [ p=[p=1 q=10]
348 q
349 [ ~
350 u
351 [ p=[%cnhp p=[%wing p=~[%add]] q=~[[%sand p=%ud q=2] [%sand p=%ud q=2]]]
352 q=[p=[p=1 q=10] q=""]
353 ]
354 ]
355 ]
357 > (wonk (wide:vast [1 1] "(add 2 2)"))
358 [%cnhp p=[%wing p=~[%add]] q=~[[%sand p=%ud q=2] [%sand p=%ud q=2]]]
359```
361#### Discussion
363See also: `++edge`
365---