on 4fdc19d help sign in
486 lines 5.8 kB history raw
1+++
2title = "4m: Formatting Functions"
3weight = 40
4template = "doc.html"
5+++
7## `++scot`
9Render dime as cord
11Renders a dime `mol` as a cord.
13#### Accepts
15`mol` is a `dime`.
17#### Produces
19A `cord`.
21#### Source
23```hoon
24++ scot
25 ~/ %scot
26 |=(mol=dime ~(rent co %$ mol))
27```
29#### Examples
31```
32> (scot %p ~pillyt)
33~.~pillyt
35> `@t`(scot %p ~pillyt)
36'~pillyt'
38> `@t`(scot %ux 0x12)
39'0x12'
41> `@t`(scot %if .127.0.0.1)
42'.127.0.0.1'
44> `@t`(scot %ta ~.asd_a)
45'~.asd_a'
46```
48---
50## `++scow`
52Render dime as tape
54Renders a dime `mol` as a tape.
56#### Accepts
58`mol` is a `dime`.
60#### Produces
62A `tape`.
64#### Source
66```hoon
67++ scow
68 ~/ %scow
69 |=(mol=dime ~(rend co %$ mol))
70```
72#### Examples
74```
75> (scow %p ~pillyt)
76"~pillyt"
78> (scow %ux 0x12)
79"0x12"
81> (scow %if .127.0.0.1)
82".127.0.0.1"
84> (scow %ta ~.asd_a)
85"~.asd_a"
86```
88---
90## `++slat`
92Curried slaw
94Produces a `gate` that parses a `knot` `txt` to a `unit` containing the atom of
95the aura specified by `mod`. The `unit` will be null if parsing failed.
97#### Accepts
99`mod` is a `knot`.
101`txt` is a `cord`.
103#### Produces
105A `(unit @)`.
107#### Source
109```hoon
110++ slat |=(mod=@tas |=(txt=@ta (slaw mod txt)))
111```
113#### Examples
115```
116> `(unit @p)`((slat %p) '~pillyt')
117[~ ~pillyt]
119> `(unit @ux)`((slat %ux) '0x12')
120[~ 0x12]
122> `(unit @if)`((slat %if) '.127.0.0.1')
123[~ .127.0.0.1]
125> `(unit @ta)`((slat %ta) '~.asd_a')
126[~ ~.asd_a]
127```
129---
131## `++slav`
133Demand: parse cord with input aura
135Parses a cord `txt` to an atom of the aura specificed by `mod`.
136Crashes if it fails to parse.
138#### Accepts
140`mod` is a `term`
142`txt` is a `knot`.
144#### Produces
146an atom.
148#### Source
150```hoon
151++ slav |=([mod=@tas txt=@ta] (need (slaw mod txt)))
152```
154#### Examples
156```
157> `@p`(slav %p '~pillyt')
158~pillyt
160> `@p`(slav %p '~pillam')
161! exit
163> `@ux`(slav %ux '0x12')
1640x12
166> `@ux`(slav %ux '0b10')
167! exit
169> `@if`(slav %if '.127.0.0.1')
170.127.0.0.1
172> `@if`(slav %if '.fe80.0.0.202')
173! exit
175> `@ta`(slav %ta '~.asd_a')
176~.asd_a
178> `@ta`(slav %ta '~~asd-a')
179! exit
180```
182---
184## `++slaw`
186Parse cord to input aura
188Parses a cord `txt` to a `unit` containing the atom of the aura specified by
189`mod`. The `unit` is null if parsing failed.
191#### Accepts
193`mod` is a `term`.
195`txt` is a `knot`.
197#### Produces
199A `(unit @)`.
201#### Source
203```hoon
204++ slaw
205 ~/ %slaw
206 |= [mod=@tas txt=@ta]
207 ^- (unit @)
208 ?+ mod
209 :: slow fallback case to the full slay
210 ::
211 =+ con=(slay txt)
212 ?.(&(?=([~ %$ @ @] con) =(p.p.u.con mod)) ~ [~ q.p.u.con])
213 ::
214 %da
215 (rush txt ;~(pfix sig (cook year when:so)))
216 ::
217 %p
218 (rush txt ;~(pfix sig fed:ag))
219 ::
220 %ud
221 (rush txt dem:ag)
222 ::
223 %ux
224 (rush txt ;~(pfix (jest '0x') hex:ag))
225 ::
226 %uv
227 (rush txt ;~(pfix (jest '0v') viz:ag))
228 ::
229 %ta
230 (rush txt ;~(pfix ;~(plug sig dot) urs:ab))
231 ::
232 %tas
233 (rush txt sym)
234 ==
235```
237#### Examples
239```
240> `(unit @p)`(slaw %p '~pillyt')
241[~ ~pillyt]
243> `(unit @p)`(slaw %p '~pillam')
246> `(unit @ux)`(slaw %ux '0x12')
247[~ 0x12]
249> `(unit @ux)`(slaw %ux '0b10')
252> `(unit @if)`(slaw %if '.127.0.0.1')
253[~ .127.0.0.1]
255> `(unit @if)`(slaw %if '.fe80.0.0.202')
258> `(unit @ta)`(slaw %ta '~.asd_a')
259[~ ~.asd_a]
261> `(unit @ta)`(slaw %ta '~~asd-a')
263```
265---
267## `++slay`
269Parse cord to coin
271Parses a cord `txt` to the unit of a `coin`.
273#### Accepts
275`txt` is a `@ta`.
277#### Produces
279A `(unit coin)`.
281#### Source
283```hoon
284++ slay
285 |= txt=@ta ^- (unit coin)
286 =+ ^= vex
287 ?: (gth 0x7fff.ffff txt) :: XX petty cache
288 ~+ ((full nuck:so) [[1 1] (trip txt)])
289 ((full nuck:so) [[1 1] (trip txt)])
290 ?~ q.vex
291 ~
292 [~ p.u.q.vex]
293```
295#### Examples
297```
298> (slay '~pillyt')
299[~ [%$ p=[p=~.p q=13.184]]]
301> (slay '0x12')
302[~ [%$ p=[p=~.ux q=18]]]
304> (slay '.127.0.0.1')
305[~ [%$ p=[p=~.if q=2.130.706.433]]]
307> (slay '!')
309```
311---
313## `++smyt`
315Render path as tank
317Renders the path `bon` as a `tank`, which is used for
318pretty-printing.
320#### Accepts
322`bon` is a `path`.
324#### Produces
326A `tank`.
328#### Source
330```hoon
331++ smyt
332 |= bon=path ^- tank
333 :+ %rose [['/' ~] ['/' ~] ~]
334 (turn bon |=(a=@ [%leaf (trip a)]))
335```
337#### Examples
339```
340> (smyt %)
341[ %rose
342 p=[p="/" q="/" r=""]
343 q
344 ~[
345 [%leaf p="~zod"]
346 [%leaf p="base"]
347 [%leaf p="~2022.1.6..14.22.14..40bf"]
348 ]
351> (smyt /as/les/top)
352[ %rose
353 p=[p="/" q="/" r=""]
354 q=~[[%leaf p="as"] [%leaf p="les"] [%leaf p="top"]]
356```
358---
360## `++spat`
362Render path as cord
364Renders a path `pax` as cord.
366#### Accepts
368`pax` is a `path`.
370#### Produces
372A `cord`.
374#### Source
376```hoon
377++ spat |=(pax=path (crip (spud pax)))
378```
380#### Examples
382```
383> (spat %)
384'/~zod/base/~2022.1.6..14.23.31..e367'
386> (spat %/lib)
387'/~zod/base/~2022.1.6..14.23.43..829e/lib'
389> (spat /as/les/top)
390'/as/les/top'
391```
393---
395## `++spud`
397Render path as tape
399Renders a path `pax` as tape.
401#### Accepts
403`pax` is a `path`.
405#### Produces
407A `tape`.
409#### Source
411```hoon
412++ spud |=(pax=path ~(ram re (smyt pax)))
413```
415#### Examples
417```
418> (spud %)
419"/~zod/base/~2022.1.6..14.24.35..cddf"
421> (spud %/lib)
422"/~zod/base/~2022.1.6..14.24.43..3efb/lib"
424> (spud /as/les/top)
425"/as/les/top"
426```
428---
430## `++stab`
432Parse cord to path
434Parses a cord `zep` to a static `path`.
435Crashes if it fails to parse.
437#### Accepts
439`zep` is a `@t`.
441#### Produces
443A `path`, or crash.
445#### Source
447```hoon
448++ stab |=(zep=@t `path`(rash zep stap))
449```
451#### Examples
453```
454> (stab '/as/lek/tor')
455/as/lek/tor
456```
458---
460## `++stap`
462Path parser
464Parsing `rule`. Parses a `path`, used internally by `++stab`.
466#### Source
468```hoon
469++ stap
470 %+ sear
471 |= p=path
472 ^- (unit path)
473 ?: ?=([~ ~] p) `~
474 ?. =(~ (rear p)) `p
475 ~
476 ;~(pfix fas (most fas urs:ab))
477```
479#### Examples
481```
482> (scan "/foo/bar/baz" stap)
483/foo/bar/baz
484```
486---