on 4fdc19d help sign in
396 lines 7.8 kB history raw
1+++
2title = "4c: Tank Printer"
3weight = 30
4template = "doc.html"
5+++
7## `++wash`
9Render tank at width
11Render `tac` with indent `tab` and maximum width `edg`. If `tac` cannot be
12rendered in-line in less than `tac` characters, it will be split into multiple
13lines if possible. If `tac` cannot be made to fit, `wash` will crash.
15#### Accepts
17`[tab=@ edg=@]` - `tab` is the number of characters of indentation and `edge` is
18the maximum number of characters of width.
20`tac` is a `tank`.
22#### Produces
24A `wall` (list of `tape`s).
26#### Source
28```hoon
29++ wash
30 |= [[tab=@ edg=@] tac=tank] ^- wall
31 (~(win re tac) tab edg)
32```
34#### Examples
36```
37> =rose `tank`[%rose [" " "[" "]"] ~['abc' 'def' 'ghi']]
39> ((slog (crip (of-wall:format (wash [0 80] rose))) ~) ~)
40[abc def ghi]
43> ((slog (crip (of-wall:format (wash [0 8] rose))) ~) ~)
44[ abc
45 def
46 ghi
49> ((slog (crip (of-wall:format (wash [3 15] rose))) ~) ~)
50 [ abc
51 def
52 ghi
53 ]
54```
56## `++re`
58Pretty-printing engine
60Container core for a pretty-printing engine that accepts a `tank` sample and contains arms that perform computation on it.
62#### Accepts
64`tac` is a `tank`.
66#### Source
68```hoon
69++ re
70 |_ tac=tank
71```
73---
75### `++ram:re`
77Flatten to tape
79Flatten `tank` out into a `tape`.
81#### Accepts
83`tac` is a `tank`, taken from sample of `++re` core.
85#### Produces
87A `tape`.
89#### Source
91```hoon
92++ ram
93 ^- tape
94 ?@ tac
95 (trip tac)
96 ?- -.tac
97 %leaf p.tac
98 ::
99 :: flat %palm rendered as %rose with welded openers
100 ::
101 %palm
102 =* mid p.p.tac
103 =* for (weld q.p.tac r.p.tac)
104 =* end s.p.tac
105 ram(tac [%rose [mid for end] q.tac])
106 ::
107 :: flat %rose rendered with open/mid/close
108 ::
109 %rose
110 =* mid p.p.tac
111 =* for q.p.tac
112 =* end r.p.tac
113 =* lit q.tac
114 %+ weld
115 for
116 |- ^- tape
117 ?~ lit
118 end
119 %+ weld
120 ram(tac i.lit)
121 =* voz $(lit t.lit)
122 ?~(t.lit voz (weld mid voz))
123 ==
124```
126#### Examples
128```
129> ~(ram re leaf+"foo")
130"foo"
132> ~(ram re [%rose [" " "[" "]"] ~['abc' 'def' 'ghi']])
133"[abc def ghi]"
134```
136---
138### `++win:re`
140Render at indent
142Render at indent level `tab` and width `edg`.
144#### Accepts
146`tac` is a `tank`, taken from sample of `++re` core.
148`tab` and `edg` are atoms.
150#### Produces
152A `wall` (list of `tape`).
154#### Source
156```hoon
157++ win
158 |= [tab=@ud edg=@ud]
159 :: output stack
160 ::
161 =| lug=wall
162 |^ ^- wall
163 ?@ tac
164 (rig (trip tac))
165 ?- -.tac
166 %leaf (rig p.tac)
167 ::
168 %palm
169 =/ hom ram
170 ?: (lte (lent hom) (sub edg tab))
171 (rig hom)
172 ::
173 =* for q.p.tac
174 =* lit q.tac
175 ?~ lit
176 (rig for)
177 ?~ t.lit
178 =: tab (add 2 tab)
179 lug $(tac i.lit)
180 ==
181 (rig for)
182 ::
183 => .(lit `(list tank)`lit)
184 =/ lyn (mul 2 (lent lit))
185 =. lug
186 |- ^- wall
187 ?~ lit
188 lug
189 =/ nyl (sub lyn 2)
190 %= ^$
191 tac i.lit
192 tab (add tab nyl)
193 lug $(lit t.lit, lyn nyl)
194 ==
195 (wig for)
196 ::
197 %rose
198 =/ hom ram
199 ?: (lte (lent hom) (sub edg tab))
200 (rig hom)
201 ::
202 =* for q.p.tac
203 =* end r.p.tac
204 =* lit q.tac
205 =. lug
206 |- ^- wall
207 ?~ lit
208 ?~(end lug (rig end))
209 %= ^$
210 tac i.lit
211 tab (mod (add 2 tab) (mul 2 (div edg 3)))
212 lug $(lit t.lit)
213 ==
214 ?~(for lug (wig for))
215 ==
216 :: +rig: indent tape and cons with output stack
217 ::
218 ++ rig
219 |= hom=tape
220 ^- wall
221 [(runt [tab ' '] hom) lug]
222 :: +wig: indent tape and cons with output stack
223 ::
224 :: joined with the top line if whitespace/indentation allow
225 ::
226 ++ wig
227 |= hom=tape
228 ^- wall
229 ?~ lug
230 (rig hom)
231 =/ wug :(add 1 tab (lent hom))
232 ?. =+ mir=i.lug
233 |- ^- ?
234 ?~ mir |
235 ?| =(0 wug)
236 ?&(=(' ' i.mir) $(mir t.mir, wug (dec wug)))
237 ==
238 (rig hom) :: ^ XX regular form?
239 :_ t.lug
240 %+ runt [tab ' ']
241 (weld hom `tape`[' ' (slag wug i.lug)])
242 --
243```
245#### Examples
247```
248> =rose `tank`[%rose [" " "[" "]"] ~['abc' 'def' 'ghi']]
250> ((slog (crip (of-wall:format (~(win re rose) 0 80))) ~) ~)
251[abc def ghi]
253> ((slog (crip (of-wall:format (~(win re rose) 3 80))) ~) ~)
254 [abc def ghi]
256> ((slog (crip (of-wall:format (~(win re rose) 0 10))) ~) ~)
257[ abc
258 def
259 ghi
262> ((slog (crip (of-wall:format (~(win re rose) 3 15))) ~) ~)
263 [ abc
264 def
265 ghi
266 ]
267```
269---
271## `++show`
273Pretty-printer (deprecated)
275Pretty prints noun `vem`, producing a `tank`. This function is deprecated and in
276most cases produces outdated syntax or incorrect results.
278#### Accepts
280`vem` is a noun.
282#### Produces
284A `tank`.
286#### Source
288```hoon
289++ show
290 |= vem=*
291 |^ ^- tank
292 ?: ?=(@ vem)
293 [%leaf (mesc (trip vem))]
294 ?- vem
295 [s=~ c=*]
296 [%leaf '\'' (weld (mesc (tape +.vem)) `tape`['\'' ~])]
297 ::
298 [s=%a c=@] [%leaf (mesc (trip c.vem))]
299 [s=%b c=*] (shop c.vem |=(a=@ ~(rub at a)))
300 [s=[%c p=@] c=*]
301 :+ %palm
302 [['.' ~] ['-' ~] ~ ~]
303 [[%leaf (mesc (trip p.s.vem))] $(vem c.vem) ~]
304 ::
305 [s=%d c=*] (shop c.vem |=(a=@ ~(rud at a)))
306 [s=%k c=*] (tank c.vem)
307 [s=%h c=*]
308 :+ %rose
309 [['/' ~] ['/' ~] ~]
310 =+ yol=((list @ta) c.vem)
311 (turn yol |=(a=@ta [%leaf (trip a)]))
312 ::
313 [s=%l c=*] (shol c.vem)
314 [s=%o c=*]
315 %= $
316 vem
317 :- [%m '%h::[%d %d].[%d %d]>']
318 [-.c.vem +<-.c.vem +<+.c.vem +>-.c.vem +>+.c.vem ~]
319 ==
320 ::
321 [s=%p c=*] (shop c.vem |=(a=@ ~(rup at a)))
322 [s=%q c=*] (shop c.vem |=(a=@ ~(r at a)))
323 [s=%r c=*] $(vem [[%r ' ' '{' '}'] c.vem])
324 [s=%t c=*] (shop c.vem |=(a=@ ~(rt at a)))
325 [s=%v c=*] (shop c.vem |=(a=@ ~(ruv at a)))
326 [s=%x c=*] (shop c.vem |=(a=@ ~(rux at a)))
327 [s=[%m p=@] c=*] (shep p.s.vem c.vem)
328 [s=[%r p=@] c=*]
329 $(vem [[%r ' ' (cut 3 [0 1] p.s.vem) (cut 3 [1 1] p.s.vem)] c.vem])
330 ::
331 [s=[%r p=@ q=@ r=@] c=*]
332 :+ %rose
333 :* p=(mesc (trip p.s.vem))
334 q=(mesc (trip q.s.vem))
335 r=(mesc (trip r.s.vem))
336 ==
337 |- ^- (list tank)
338 ?@ c.vem
339 ~
340 [^$(vem -.c.vem) $(c.vem +.c.vem)]
341 ::
342 [s=%z c=*] $(vem [[%r %$ %$ %$] c.vem])
343 * !!
344 ==
345 ++ shep
346 |= [fom=@ gar=*]
347 ^- tank
348 =+ l=(met 3 fom)
349 =+ i=0
350 :- %leaf
351 |- ^- tape
352 ?: (gte i l)
353 ~
354 =+ c=(cut 3 [i 1] fom)
355 ?. =(37 c)
356 (weld (mesc [c ~]) $(i +(i)))
357 =+ d=(cut 3 [+(i) 1] fom)
358 ?. .?(gar)
359 ['\\' '#' $(i (add 2 i))]
360 (weld ~(ram re (show d -.gar)) $(i (add 2 i), gar +.gar))
361 ::
362 ++ shop
363 |= [aug=* vel=$-(a=@ tape)]
364 ^- tank
365 ?: ?=(@ aug)
366 [%leaf (vel aug)]
367 :+ %rose
368 [[' ' ~] ['[' ~] [']' ~]]
369 => .(aug `*`aug)
370 |- ^- (list tank)
371 ?: ?=(@ aug)
372 [^$ ~]
373 [^$(aug -.aug) $(aug +.aug)]
374 ::
375 ++ shol
376 |= lim=*
377 :+ %rose
378 [['.' ~] ~ ~]
379 |- ^- (list tank)
380 ?: ?=(@ lim) ~
381 :_ $(lim +.lim)
382 ?+ -.lim (show '#')
383 ~ (show '$')
384 c=@ (show c.lim)
385 [%& %1] (show '.')
386 [%& c=@]
387 [%leaf '+' ~(rud at c.lim)]
388 ::
389 [%| @ ~] (show ',')
390 [%| n=@ ~ c=@]
391 [%leaf (weld (reap n.lim '^') ?~(c.lim "$" (trip c.lim)))]
392 ==
393 --
394```
396---