on dc20522 help sign in
434 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```
49---
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```
69#### Examples
71```
72 > (scow %p ~pillyt)
73 "~pillyt"
74 > (scow %ux 0x12)
75 "0x12"
76 > (scow %if .127.0.0.1)
77 ".127.0.0.1"
78 > (scow %ta ~.asd_a)
79 "~.asd_a"
80```
83---
84### `++slat`
86Curried slaw
88Produces a `gate` that parses a `term` `txt` to an atom of the
89odor specified by `mod`.
91#### Accepts
93`mod` is a term, an atom of odor `@tas`.
95`txt` is a cord, an atom of odor `@ta`.
97#### Produces
99A `gate`.
101#### Source
103```hoon
104 ++ slat |=(mod/@tas |=(txt/@ta (slaw mod txt)))
105```
107#### Examples
109```
110 > `(unit @p)`((slat %p) '~pillyt')
111 [~ ~pillyt]
112 > `(unit @ux)`((slat %ux) '0x12')
113 [~ 0x12]
114 > `(unit @if)`((slat %if) '.127.0.0.1')
115 [~ .127.0.0.1]
116 > `(unit @ta)`((slat %ta) '~.asd_a')
117 [~ ~.asd_a
118```
121---
122### `++slav`
124Demand: parse cord with input odor
126Parses a cord `txt` to an atom of the odor specificed by `mod`.
127Crashes if it fails to parse.
129#### Accepts
131`mod` is a term, an atom of odor `@tas`.
133`txt` is a cord, an atom of odor `@ta`.
135#### Produces
137The atom of a `(unit @)` from `++slaw`, or crash.
139#### Source
141```hoon
142 ++ slav |=([mod/@tas txt/@ta] (need (slaw mod txt)))
143```
145#### Examples
147```
148 > `@p`(slav %p '~pillyt')
149 ~pillyt
150 > `@p`(slav %p '~pillam')
151 ! exit
152 > `@ux`(slav %ux '0x12')
153 0x12
154 > `@ux`(slav %ux '0b10')
155 ! exit
156 > `@if`(slav %if '.127.0.0.1')
157 .127.0.0.1
158 > `@if`(slav %if '.fe80.0.0.202')
159 ! exit
160 > `@ta`(slav %ta '~.asd_a')
161 ~.asd_a
162 > `@ta`(slav %ta '~~asd-a')
163 ! exit
164```
166---
167### `++slaw`
169Parse cord to input odor
171Parses a cord `txt` to an atom of the odor specified by `mod`.
173#### Accepts
175`mod` is a term, an atom of odor `@tas`.
177`txt` is a cord, an atom of odor `@ta`.
179#### Produces
181A `(unit @)`.
183#### Source
185```hoon
186 ++ slaw
187 ~/ %slaw
188 |= {mod/@tas txt/@ta}
189 ^- (unit @)
190 =+ con=(slay txt)
191 ?.(&(?=({$~ $$ @ @} con) =(p.p.u.con mod)) ~ [~ q.p.u.con])
192```
194#### Examples
196```
197 > `(unit @p)`(slaw %p '~pillyt')
198 [~ ~pillyt]
199 > `(unit @p)`(slaw %p '~pillam')
200 ~
201 > `(unit @ux)`(slaw %ux '0x12')
202 [~ 0x12]
203 > `(unit @ux)`(slaw %ux '0b10')
204 ~
205 > `(unit @if)`(slaw %if '.127.0.0.1')
206 [~ .127.0.0.1]
207 > `(unit @if)`(slaw %if '.fe80.0.0.202')
208 ~
209 > `(unit @ta)`(slaw %ta '~.asd_a')
210 [~ ~.asd_a]
211 > `(unit @ta)`(slaw %ta '~~asd-a')
212 ~
213```
216---
217### `++slay`
219Parse cord to coin
221Parses a cord `txt` to the unit of a `++coin`.
223#### Accepts
225`txt` is a `@ta`.
227#### Produces
229A `(unit coin)`.
231#### Source
233```hoon
234 ++ slay
235 |= txt/@ta ^- (unit coin)
236 =+ ^= vex
237 ?: (gth 0x7fff.ffff txt) :: XX petty cache
238 ~+ ((full nuck:so) [[1 1] (trip txt)])
239 ((full nuck:so) [[1 1] (trip txt)])
240 ?~ q.vex
241 ~
242 [~ p.u.q.vex]
243 ::
244```
246#### Examples
248```
249 > (slay '~pillyt')
250 [~ [% p=[p=~.p q=32.819]]]
251 > (slay '0x12')
252 [~ [% p=[p=~.ux q=18]]]
253 > (slay '.127.0.0.1')
254 [~ [% p=[p=~.if q=2.130.706.433]]]
255 > `@ud`.127.0.0.1
256 2.130.706.433
257 > (slay '._20_0w25_sam__')
258 [ ~
259 [ %many
260 p=~[[% p=[p=~.ud q=20]] [% p=[p=~.uw q=133]] [% p=[p=~.tas q=7.168.371]]]
261 ]
262 ]
263 > `@`%sam
264 7.168.371
265 > (slay '~0ph')
266 [~ [%blob p=[1 1]]]
267 > 0ph
268 ~ <syntax error at [1 2]>
269 > ~0ph
270 [1 1]
271 > `@uv`(jam [1 1])
272 0vph
273```
276---
277### `++smyt`
279Render path as tank
281Renders the path `bon` as a `tank`, which is used for
282pretty-printing.
284#### Accepts
286`bon` is a `++path`.
288#### Produces
290A `tank`.
292#### Source
294```hoon
295 ++ smyt :: pretty print path
296 |= bon/path ^- tank
297 :+ %rose [['/' ~] ['/' ~] ~]
298 (turn bon |=(a/@ [%leaf (trip a)]))
299 ::
300```
302#### Examples
304```
305 > (smyt %)
306 [ %rose
307 p=[p="/" q="/" r="/"]
308 q
309 ~[ [%leaf p="~zod"]
310 [%leaf p="try"]
311 [%leaf p="~2014.10.28..18.36.58..a280"]
312 ]
313 ]
314 > (smyt /as/les/top)
315 [ %rose
316 p=[p="/" q="/" r="/"]
317 q=~[[%leaf p="as"] [%leaf p="les"] [%leaf p="top"]]
318 ]
319```
322---
323### `++spat`
325Render path as cord
327Renders a path `pax` as cord.
329#### Accepts
331`pax` is a `path`.
333#### Produces
335A `cord`.
337#### Source
339```hoon
340 ++ spat |=(pax/path (crip (spud pax))) :: path to cord
341```
343#### Examples
345```
346 > (spat %)
347 '~zod/try/~2014.10.28..18.40.20..4287'
348 > (spat %/bin)
349 '~zod/try/~2014.10.28..18.41.12..3bcd/bin'
350 > (spat /as/les/top)
351 '/as/les/top'
352```
355---
356### `++spud`
358Render path as tape
360Renders a path `pax` as tape.
362#### Accepts
364`pax` is a `path`.
366#### Produces
368A `tape`.
370#### Source
372```hoon
373 ++ spud |=(pax/path ~(ram re (smyt pax))) :: path to tape
374```
376#### Examples
378```
379 > (spud %)
380 "~zod/try/~2014.10.28..18.40.46..e951"
381 > (spud %/bin)
382 "~zod/try/~2014.10.28..18.41.05..16f2/bin"
383 > (spud /as/les/top)
384 "/as/les/top"
385```
388---
389### `++stab`
391Parse cord to path
393Parsing rule. Parses a cord `zep` to a static `++path`.
394Crashes if it fails to parse.
396#### Accepts
398`zep` is a `@t`.
400#### Produces
402A `path`, or crash.
404#### Source
406```hoon
407 ++ stab :: parse cord to path
408 =+ fel=;~(pfix fas (more fas urs:ab))
409 |=(zep/@t `path`(rash zep fel))
410```
412#### Examples
414```
415 > (stab '/as/lek/tor')
416 /as/lek/tor
418 > `(pole ,@ta)`(stab '/as/lek/tor')
419 [~.as [~.lek [~.tor ~]]]
421 > (stab '~zod/arvo/~2014.10.28..18.48.41..335f/zuse')
422 ~zod/arvo/~2014.10.28..18.48.41..335f/zuse
424 > `(pole ,@ta)`(stab '~zod/arvo/~2014.10.28..18.48.41..335f/zuse')
425 [~.~zod [~.arvo [~.~2014.10.28..18.48.41..335f [~.zuse ~]]]]
427 > (stab '/a/~pillyt/pals/1')
428 /a/~pillyt/pals/1
430 > `(pole ,@ta)`(stab '/a/~pillyt/pals/1')
431 [~.a [~.~pillyt [~.pals [~.1 ~]]]]
432```
434---