on 883cb21 help sign in
360 lines 7.5 kB history raw
1+++
2title = "4c: Tank Printer"
3weight = 30
4template = "doc.html"
5+++
7## `++re`
9Pretty-printing engine
11Pretty-printing engine that accepts a `++tank` sample and contains arms that perform computation on it.
13#### Accepts
15`tac` is a `++tank`.
17#### Produces
19```hoon
20 ++ re
21 |_ tac/tank
22```
24#### Examples
26```
27 > ~(. re leaf+"ham")
28 <2.gdc {tac/{$leaf ""} <402.arm 110.jyx 1.ztu $151>}>
29```
31---
33### `++ram:re`
35Flatten to tape
37Flatten `++tank` out into a `++tape`.
39#### Accepts
41`tac` is a `++tank`, taken from sample of `++re` core.
43#### Produces
45A `++tape`.
47#### Source
49```hoon
50 ++ ram
51 ^- tape
52 ?- -.tac
53 $leaf p.tac
54 $palm ram(tac [%rose [p.p.tac (weld q.p.tac r.p.tac) s.p.tac] q.tac])
55 $rose
56 %+ weld
57 q.p.tac
58 |- ^- tape
59 ?~ q.tac
60 r.p.tac
61 =+ voz=$(q.tac t.q.tac)
62 (weld ram(tac i.q.tac) ?~(t.q.tac voz (weld p.p.tac voz)))
63 ==
64 ::
65```
67#### Examples
69```
70 > ~(ram re leaf+"foo")
71 "foo"
72 > ~(ram re rose+["." "(" ")"]^~[leaf+"bar" leaf+"baz" leaf+"bam"])
73 "(bar.baz.bam)"
74```
76---
78### `++win:re`
80Render at indent
82Render at indent level `tab` and width `edg`.
84#### Accepts
86`tac` is a `++tank`, taken from sample of `++re` core.
88`tab` and `edg` are atoms.
90#### Produces
92A `++wall` (`++list` of `++tapes`).
94#### Source
96```hoon
97 ++ win
98 |= {tab/@ edg/@}
99 =+ lug=`wall`~
100 |^ |- ^- wall
101 ?- -.tac
102 $leaf (rig p.tac)
103 $palm
104 ?: fit
105 (rig ram)
106 ?~ q.tac
107 (rig q.p.tac)
108 ?~ t.q.tac
109 (rig(tab (add 2 tab), lug $(tac i.q.tac)) q.p.tac)
110 => .(q.tac `(list tank)`q.tac)
111 =+ lyn=(mul 2 (lent q.tac))
112 =+ ^= qyr
113 |- ^- wall
114 ?~ q.tac
115 lug
116 %= ^$
117 tac i.q.tac
118 tab (add tab (sub lyn 2))
119 lug $(q.tac t.q.tac, lyn (sub lyn 2))
120 ==
121 (wig(lug qyr) q.p.tac)
122 ::
123```
125#### Examples
127```
128 > (~(win re leaf+"samoltekon-lapdok") 0 20)
129 <<"samoltekon-lapdok">>
131 > (~(win re leaf+"samoltekon-lapdok") 0 10)
132 <<"\/samolt\/" " ekon-l" " apdok" "\/ \/">>
134 > (~(win re rose+["--" "[" "]"]^~[leaf+"1423" leaf+"2316"]) 0 20)
135 <<"[1423--2316]">>
137 > (~(win re rose+["--" "[" "]"]^~[leaf+"1423" leaf+"2316"]) 0 10)
138 <<"[ 1423" " 2316" "]">>
139```
141---
143### `++din:re`
145XX document
147#### Accepts
149#### Produces
151#### Source
153 ++ din (mod (add 2 tab) (mul 2 (div edg 3)))
155---
157### `++fit:re`
159Fit on one line test
161Determine whether `tac` fits on one line. Internal to `++win`
163#### Accepts
165#### Produces
167#### Source
169++ fit (lte (lent ram) (sub edg tab))
171#### Examples
173---
175### `++rig:re`
177Wrap in `\/`
179Wrap `++tape` in `\/` if it doesn't fit at current indentation. Internal to
180`++win`
182#### Accepts
184`tac` is a `++tank`, taken from sample of `++re` core.
186`hom` is a `++tape`.
188#### Produces
190A `++wall` (list of `++tape`s).
192#### Source
194```hoon
195 ++ rig
196 |= hom/tape
197 ^- wall
198 ?: & ::(lte (lent hom) (sub edg tab))
199 [(runt [tab ' '] hom) lug]
200 => .(tab (add tab 2), edg (sub edg 2))
201 =+ mut=(trim (sub edg tab) hom)
202 :- (runt [(sub tab 2) ' '] ['\\' '/' (weld p.mut `_hom`['\\' '/' ~])])
203 => .(hom q.mut)
204 |-
205 ?~ hom
206 :- %+ runt
207 [(sub tab 2) ' ']
208 ['\\' '/' (runt [(sub edg tab) ' '] ['\\' '/' ~])]
209 lug
210 => .(mut (trim (sub edg tab) hom))
211 [(runt [tab ' '] p.mut) $(hom q.mut)]
212 ::
213```
215#### Examples
217---
219### `++wig:re`
221`++win` render tape
223Render `++tape`. Internal to `++win`.
225#### Accepts
227`tac` is a `++tank`, taken from sample of `++re` core.
229`hom` is a `++tape`.
231#### Produces
233```hoon
234 ++ wig
235 |= hom/tape
236 ^- wall
237 ?~ lug
238 (rig hom)
239 =+ lin=(lent hom)
240 =+ wug=:(add 1 tab lin)
241 ?. =+ mir=i.lug
242 |- ?~ mir
243 |
244 ?|(=(0 wug) ?&(=(' ' i.mir) $(mir t.mir, wug (dec wug))))
245 (rig hom) :: ^ XX regular form?
246 [(runt [tab ' '] (weld hom `tape`[' ' (slag wug i.lug)])) t.lug]
247 --
248 --
249```
251---
253## `++show`
255```hoon
256 ++ show :: XX deprecated, use span
257 |= vem/*
258 |^ ^- tank
259 ?: ?=(@ vem)
260 [%leaf (mesc (trip vem))]
261 ?- vem
262 {s/$~ c/*}
263 [%leaf '\'' (weld (mesc (tape +.vem)) `tape`['\'' ~])]
264 ::
265 {s/$a c/@} [%leaf (mesc (trip c.vem))]
266 {s/$b c/*} (shop c.vem |=(a/@ ~(rub at a)))
267 {s/{$c p/@} c/*}
268 :+ %palm
269 [['.' ~] ['-' ~] ~ ~]
270 [[%leaf (mesc (trip p.s.vem))] $(vem c.vem) ~]
271 ::
272 {s/$d c/*} (shop c.vem |=(a/@ ~(rud at a)))
273 {s/$k c/*} (tank c.vem)
274 {s/$h c/*}
275 :+ %rose
276 [['/' ~] ['/' ~] ~]
277 =+ yol=((list @ta) c.vem)
278 (turn yol |=(a/@ta [%leaf (trip a)]))
279 ::
280 {s/$l c/*} (shol c.vem)
281 {s/$o c/*}
282 %= $
283 vem
284 :- [%m '%h:<[%d %d].[%d %d]>']
285 [-.c.vem +<-.c.vem +<+.c.vem +>-.c.vem +>+.c.vem ~]
286 ==
287 ::
288 {s/$p c/*} (shop c.vem |=(a/@ ~(rup at a)))
289 {s/$q c/*} (shop c.vem |=(a/@ ~(r at a)))
290 {s/$r c/*} $(vem [[%r ' ' '{' '}'] c.vem])
291 {s/$t c/*} (shop c.vem |=(a/@ ~(rt at a)))
292 {s/$v c/*} (shop c.vem |=(a/@ ~(ruv at a)))
293 {s/$x c/*} (shop c.vem |=(a/@ ~(rux at a)))
294 {s/{$m p/@} c/*} (shep p.s.vem c.vem)
295 {s/{$r p/@} c/*}
296 $(vem [[%r ' ' (cut 3 [0 1] p.s.vem) (cut 3 [1 1] p.s.vem)] c.vem])
297 ::
298 {s/{$r p/@ q/@ r/@} c/*}
299 :+ %rose
300 :* p=(mesc (trip p.s.vem))
301 q=(mesc (trip q.s.vem))
302 r=(mesc (trip r.s.vem))
303 ==
304 |- ^- (list tank)
305 ?@ c.vem
306 ~
307 [^$(vem -.c.vem) $(c.vem +.c.vem)]
308 ::
309 {s/$z c/*} $(vem [[%r %$ %$ %$] c.vem])
310 * !!
311 ==
312```
314XX document
316## `++shep`
318```hoon
319 ++ shep
320 |= {fom/@ gar/*}
321 ^- tank
322 =+ l=(met 3 fom)
323 =+ i=0
324 :- %leaf
325 |- ^- tape
326 ?: (gte i l)
327 ~
328 =+ c=(cut 3 [i 1] fom)
329 ?. =(37 c)
330 (weld (mesc [c ~]) $(i +(i)))
331 =+ d=(cut 3 [+(i) 1] fom)
332 ?. .?(gar)
333 ['\\' '#' $(i (add 2 i))]
334 (weld ~(ram re (show d -.gar)) $(i (add 2 i), gar +.gar))
335 ::
336```
338XX document
340## `++shop`
342```hoon
343 ++ shop
344 |= {aug/* vel/$-(a/@ tape)}
345 ^- tank
346 ?: ?=(@ aug)
347 [%leaf (vel aug)]
348 :+ %rose
349 [[' ' ~] ['[' ~] [']' ~]]
350 => .(aug `*`aug)
351 |- ^- (list tank)
352 ?: ?=(@ aug)
353 [^$ ~]
354 [^$(aug -.aug) $(aug +.aug)]
355 ::
356```
358XX document
360---