on 883cb21 help sign in
436 lines 6.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 |=(mol/dime ~(rent co %$ mol))
25```
27#### Examples
29```
30 > (scot %p ~pillyt)
31 ~.~pillyt
32 > `@t`(scot %p ~pillyt)
33 '~pillyt'
34 > (scot %ux 0x12)
35 ~.0x12
36 > `@t`(scot %ux 0x12)
37 '0x12'
38 > (scot %if .127.0.0.1)
39 ~..127.0.0.1
40 > `@t`(scot %if .127.0.0.1)
41 '.127.0.0.1'
42 > (scot %ta ~.asd_a)
43 ~.~.asd_a
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 |=(mol/dime ~(rend co %$ mol))
68```
70#### Examples
72```
73 > (scow %p ~pillyt)
74 "~pillyt"
75 > (scow %ux 0x12)
76 "0x12"
77 > (scow %if .127.0.0.1)
78 ".127.0.0.1"
79 > (scow %ta ~.asd_a)
80 "~.asd_a"
81```
83---
85## `++slat`
87Curried slaw
89Produces a `gate` that parses a `term` `txt` to an atom of the
90aura specified by `mod`.
92#### Accepts
94`mod` is a term, an atom of aura `@tas`.
96`txt` is a cord, an atom of aura `@ta`.
98#### Produces
100A `gate`.
102#### Source
104```hoon
105 ++ slat |=(mod/@tas |=(txt/@ta (slaw mod txt)))
106```
108#### Examples
110```
111 > `(unit @p)`((slat %p) '~pillyt')
112 [~ ~pillyt]
113 > `(unit @ux)`((slat %ux) '0x12')
114 [~ 0x12]
115 > `(unit @if)`((slat %if) '.127.0.0.1')
116 [~ .127.0.0.1]
117 > `(unit @ta)`((slat %ta) '~.asd_a')
118 [~ ~.asd_a
119```
121---
123## `++slav`
125Demand: parse cord with input aura
127Parses a cord `txt` to an atom of the aura specificed by `mod`.
128Crashes if it fails to parse.
130#### Accepts
132`mod` is a term, an atom of aura `@tas`.
134`txt` is a cord, an atom of aura `@ta`.
136#### Produces
138The atom of a `(unit @)` from `++slaw`, or crash.
140#### Source
142```hoon
143 ++ slav |=([mod/@tas txt/@ta] (need (slaw mod txt)))
144```
146#### Examples
148```
149 > `@p`(slav %p '~pillyt')
150 ~pillyt
151 > `@p`(slav %p '~pillam')
152 ! exit
153 > `@ux`(slav %ux '0x12')
154 0x12
155 > `@ux`(slav %ux '0b10')
156 ! exit
157 > `@if`(slav %if '.127.0.0.1')
158 .127.0.0.1
159 > `@if`(slav %if '.fe80.0.0.202')
160 ! exit
161 > `@ta`(slav %ta '~.asd_a')
162 ~.asd_a
163 > `@ta`(slav %ta '~~asd-a')
164 ! exit
165```
167---
169## `++slaw`
171Parse cord to input aura
173Parses a cord `txt` to an atom of the aura specified by `mod`.
175#### Accepts
177`mod` is a term, an atom of aura `@tas`.
179`txt` is a cord, an atom of aura `@ta`.
181#### Produces
183A `(unit @)`.
185#### Source
187```hoon
188 ++ slaw
189 ~/ %slaw
190 |= {mod/@tas txt/@ta}
191 ^- (unit @)
192 =+ con=(slay txt)
193 ?.(&(?=({$~ $$ @ @} con) =(p.p.u.con mod)) ~ [~ q.p.u.con])
194```
196#### Examples
198```
199 > `(unit @p)`(slaw %p '~pillyt')
200 [~ ~pillyt]
201 > `(unit @p)`(slaw %p '~pillam')
202 ~
203 > `(unit @ux)`(slaw %ux '0x12')
204 [~ 0x12]
205 > `(unit @ux)`(slaw %ux '0b10')
206 ~
207 > `(unit @if)`(slaw %if '.127.0.0.1')
208 [~ .127.0.0.1]
209 > `(unit @if)`(slaw %if '.fe80.0.0.202')
210 ~
211 > `(unit @ta)`(slaw %ta '~.asd_a')
212 [~ ~.asd_a]
213 > `(unit @ta)`(slaw %ta '~~asd-a')
214 ~
215```
217---
219## `++slay`
221Parse cord to coin
223Parses a cord `txt` to the unit of a `++coin`.
225#### Accepts
227`txt` is a `@ta`.
229#### Produces
231A `(unit coin)`.
233#### Source
235```hoon
236 ++ slay
237 |= txt/@ta ^- (unit coin)
238 =+ ^= vex
239 ?: (gth 0x7fff.ffff txt) :: XX petty cache
240 ~+ ((full nuck:so) [[1 1] (trip txt)])
241 ((full nuck:so) [[1 1] (trip txt)])
242 ?~ q.vex
243 ~
244 [~ p.u.q.vex]
245 ::
246```
248#### Examples
250```
251 > (slay '~pillyt')
252 [~ [% p=[p=~.p q=32.819]]]
253 > (slay '0x12')
254 [~ [% p=[p=~.ux q=18]]]
255 > (slay '.127.0.0.1')
256 [~ [% p=[p=~.if q=2.130.706.433]]]
257 > `@ud`.127.0.0.1
258 2.130.706.433
259 > (slay '._20_0w25_sam__')
260 [ ~
261 [ %many
262 p=~[[% p=[p=~.ud q=20]] [% p=[p=~.uw q=133]] [% p=[p=~.tas q=7.168.371]]]
263 ]
264 ]
265 > `@`%sam
266 7.168.371
267 > (slay '~0ph')
268 [~ [%blob p=[1 1]]]
269 > 0ph
270 ~ <syntax error at [1 2]>
271 > ~0ph
272 [1 1]
273 > `@uv`(jam [1 1])
274 0vph
275```
277---
279## `++smyt`
281Render path as tank
283Renders the path `bon` as a `tank`, which is used for
284pretty-printing.
286#### Accepts
288`bon` is a `++path`.
290#### Produces
292A `tank`.
294#### Source
296```hoon
297 ++ smyt :: pretty print path
298 |= bon/path ^- tank
299 :+ %rose [['/' ~] ['/' ~] ~]
300 (turn bon |=(a/@ [%leaf (trip a)]))
301 ::
302```
304#### Examples
306```
307 > (smyt %)
308 [ %rose
309 p=[p="/" q="/" r="/"]
310 q
311 ~[ [%leaf p="~zod"]
312 [%leaf p="try"]
313 [%leaf p="~2014.10.28..18.36.58..a280"]
314 ]
315 ]
316 > (smyt /as/les/top)
317 [ %rose
318 p=[p="/" q="/" r="/"]
319 q=~[[%leaf p="as"] [%leaf p="les"] [%leaf p="top"]]
320 ]
321```
323---
325## `++spat`
327Render path as cord
329Renders a path `pax` as cord.
331#### Accepts
333`pax` is a `path`.
335#### Produces
337A `cord`.
339#### Source
341```hoon
342 ++ spat |=(pax/path (crip (spud pax))) :: path to cord
343```
345#### Examples
347```
348 > (spat %)
349 '~zod/try/~2014.10.28..18.40.20..4287'
350 > (spat %/bin)
351 '~zod/try/~2014.10.28..18.41.12..3bcd/bin'
352 > (spat /as/les/top)
353 '/as/les/top'
354```
356---
358## `++spud`
360Render path as tape
362Renders a path `pax` as tape.
364#### Accepts
366`pax` is a `path`.
368#### Produces
370A `tape`.
372#### Source
374```hoon
375 ++ spud |=(pax/path ~(ram re (smyt pax))) :: path to tape
376```
378#### Examples
380```
381 > (spud %)
382 "~zod/try/~2014.10.28..18.40.46..e951"
383 > (spud %/bin)
384 "~zod/try/~2014.10.28..18.41.05..16f2/bin"
385 > (spud /as/les/top)
386 "/as/les/top"
387```
389---
391## `++stab`
393Parse cord to path
395Parsing rule. Parses a cord `zep` to a static `++path`.
396Crashes if it fails to parse.
398#### Accepts
400`zep` is a `@t`.
402#### Produces
404A `path`, or crash.
406#### Source
408```hoon
409 ++ stab :: parse cord to path
410 =+ fel=;~(pfix fas (more fas urs:ab))
411 |=(zep/@t `path`(rash zep fel))
412```
414#### Examples
416```
417 > (stab '/as/lek/tor')
418 /as/lek/tor
420 > `(pole ,@ta)`(stab '/as/lek/tor')
421 [~.as [~.lek [~.tor ~]]]
423 > (stab '~zod/arvo/~2014.10.28..18.48.41..335f/zuse')
424 ~zod/arvo/~2014.10.28..18.48.41..335f/zuse
426 > `(pole ,@ta)`(stab '~zod/arvo/~2014.10.28..18.48.41..335f/zuse')
427 [~.~zod [~.arvo [~.~2014.10.28..18.48.41..335f [~.zuse ~]]]]
429 > (stab '/a/~pillyt/pals/1')
430 /a/~pillyt/pals/1
432 > `(pole ,@ta)`(stab '/a/~pillyt/pals/1')
433 [~.a [~.~pillyt [~.pals [~.1 ~]]]]
434```
436---