on dc20522 help sign in
364 lines 7.6 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---
32### `++ram:re`
34Flatten to tape
36Flatten `++tank` out into a `++tape`.
38#### Accepts
40`tac` is a `++tank`, taken from sample of `++re` core.
42#### Produces
44A `++tape`.
46#### Source
48```hoon
49 ++ ram
50 ^- tape
51 ?- -.tac
52 $leaf p.tac
53 $palm ram(tac [%rose [p.p.tac (weld q.p.tac r.p.tac) s.p.tac] q.tac])
54 $rose
55 %+ weld
56 q.p.tac
57 |- ^- tape
58 ?~ q.tac
59 r.p.tac
60 =+ voz=$(q.tac t.q.tac)
61 (weld ram(tac i.q.tac) ?~(t.q.tac voz (weld p.p.tac voz)))
62 ==
63 ::
64```
66#### Examples
68```
69 > ~(ram re leaf+"foo")
70 "foo"
71 > ~(ram re rose+["." "(" ")"]^~[leaf+"bar" leaf+"baz" leaf+"bam"])
72 "(bar.baz.bam)"
73```
74---
75### `++win:re`
77Render at indent
79Render at indent level `tab` and width `edg`.
81#### Accepts
83`tac` is a `++tank`, taken from sample of `++re` core.
85`tab` and `edg` are atoms.
87#### Produces
89A `++wall` (`++list` of `++tapes`).
91#### Source
93```hoon
94 ++ win
95 |= {tab/@ edg/@}
96 =+ lug=`wall`~
97 |^ |- ^- wall
98 ?- -.tac
99 $leaf (rig p.tac)
100 $palm
101 ?: fit
102 (rig ram)
103 ?~ q.tac
104 (rig q.p.tac)
105 ?~ t.q.tac
106 (rig(tab (add 2 tab), lug $(tac i.q.tac)) q.p.tac)
107 => .(q.tac `(list tank)`q.tac)
108 =+ lyn=(mul 2 (lent q.tac))
109 =+ ^= qyr
110 |- ^- wall
111 ?~ q.tac
112 lug
113 %= ^$
114 tac i.q.tac
115 tab (add tab (sub lyn 2))
116 lug $(q.tac t.q.tac, lyn (sub lyn 2))
117 ==
118 (wig(lug qyr) q.p.tac)
119 ::
120```
122#### Examples
124```
125 > (~(win re leaf+"samoltekon-lapdok") 0 20)
126 <<"samoltekon-lapdok">>
128 > (~(win re leaf+"samoltekon-lapdok") 0 10)
129 <<"\/samolt\/" " ekon-l" " apdok" "\/ \/">>
131 > (~(win re rose+["--" "[" "]"]^~[leaf+"1423" leaf+"2316"]) 0 20)
132 <<"[1423--2316]">>
134 > (~(win re rose+["--" "[" "]"]^~[leaf+"1423" leaf+"2316"]) 0 10)
135 <<"[ 1423" " 2316" "]">>
136```
138---
139### `++din:re`
141XX document
143#### Accepts
145#### Produces
147#### Source
149 ++ din (mod (add 2 tab) (mul 2 (div edg 3)))
152---
154### `++fit:re`
156Fit on one line test
158Determine whether `tac` fits on one line. Internal to `++win`
160#### Accepts
162#### Produces
164#### Source
166++ fit (lte (lent ram) (sub edg tab))
169#### Examples
174---
176### `++rig:re`
178Wrap in `\/`
180Wrap `++tape` in `\/` if it doesn't fit at current indentation. Internal to
181`++win`
183#### Accepts
185`tac` is a `++tank`, taken from sample of `++re` core.
187`hom` is a `++tape`.
189#### Produces
191A `++wall` (list of `++tape`s).
193#### Source
195```hoon
196 ++ rig
197 |= hom/tape
198 ^- wall
199 ?: & ::(lte (lent hom) (sub edg tab))
200 [(runt [tab ' '] hom) lug]
201 => .(tab (add tab 2), edg (sub edg 2))
202 =+ mut=(trim (sub edg tab) hom)
203 :- (runt [(sub tab 2) ' '] ['\\' '/' (weld p.mut `_hom`['\\' '/' ~])])
204 => .(hom q.mut)
205 |-
206 ?~ hom
207 :- %+ runt
208 [(sub tab 2) ' ']
209 ['\\' '/' (runt [(sub edg tab) ' '] ['\\' '/' ~])]
210 lug
211 => .(mut (trim (sub edg tab) hom))
212 [(runt [tab ' '] p.mut) $(hom q.mut)]
213 ::
214```
216#### Examples
218---
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```
253---
254### `++show`
256```hoon
257 ++ show :: XX deprecated, use span
258 |= vem/*
259 |^ ^- tank
260 ?: ?=(@ vem)
261 [%leaf (mesc (trip vem))]
262 ?- vem
263 {s/$~ c/*}
264 [%leaf '\'' (weld (mesc (tape +.vem)) `tape`['\'' ~])]
265 ::
266 {s/$a c/@} [%leaf (mesc (trip c.vem))]
267 {s/$b c/*} (shop c.vem |=(a/@ ~(rub at a)))
268 {s/{$c p/@} c/*}
269 :+ %palm
270 [['.' ~] ['-' ~] ~ ~]
271 [[%leaf (mesc (trip p.s.vem))] $(vem c.vem) ~]
272 ::
273 {s/$d c/*} (shop c.vem |=(a/@ ~(rud at a)))
274 {s/$k c/*} (tank c.vem)
275 {s/$h c/*}
276 :+ %rose
277 [['/' ~] ['/' ~] ~]
278 =+ yol=((list @ta) c.vem)
279 (turn yol |=(a/@ta [%leaf (trip a)]))
280 ::
281 {s/$l c/*} (shol c.vem)
282 {s/$o c/*}
283 %= $
284 vem
285 :- [%m '%h:<[%d %d].[%d %d]>']
286 [-.c.vem +<-.c.vem +<+.c.vem +>-.c.vem +>+.c.vem ~]
287 ==
288 ::
289 {s/$p c/*} (shop c.vem |=(a/@ ~(rup at a)))
290 {s/$q c/*} (shop c.vem |=(a/@ ~(r at a)))
291 {s/$r c/*} $(vem [[%r ' ' '{' '}'] c.vem])
292 {s/$t c/*} (shop c.vem |=(a/@ ~(rt at a)))
293 {s/$v c/*} (shop c.vem |=(a/@ ~(ruv at a)))
294 {s/$x c/*} (shop c.vem |=(a/@ ~(rux at a)))
295 {s/{$m p/@} c/*} (shep p.s.vem c.vem)
296 {s/{$r p/@} c/*}
297 $(vem [[%r ' ' (cut 3 [0 1] p.s.vem) (cut 3 [1 1] p.s.vem)] c.vem])
298 ::
299 {s/{$r p/@ q/@ r/@} c/*}
300 :+ %rose
301 :* p=(mesc (trip p.s.vem))
302 q=(mesc (trip q.s.vem))
303 r=(mesc (trip r.s.vem))
304 ==
305 |- ^- (list tank)
306 ?@ c.vem
307 ~
308 [^$(vem -.c.vem) $(c.vem +.c.vem)]
309 ::
310 {s/$z c/*} $(vem [[%r %$ %$ %$] c.vem])
311 * !!
312 ==
313```
315XX document
317### `++shep`
319```hoon
320 ++ shep
321 |= {fom/@ gar/*}
322 ^- tank
323 =+ l=(met 3 fom)
324 =+ i=0
325 :- %leaf
326 |- ^- tape
327 ?: (gte i l)
328 ~
329 =+ c=(cut 3 [i 1] fom)
330 ?. =(37 c)
331 (weld (mesc [c ~]) $(i +(i)))
332 =+ d=(cut 3 [+(i) 1] fom)
333 ?. .?(gar)
334 ['\\' '#' $(i (add 2 i))]
335 (weld ~(ram re (show d -.gar)) $(i (add 2 i), gar +.gar))
336 ::
337```
339XX document
341### `++shop`
343```hoon
344 ++ shop
345 |= {aug/* vel/$-(a/@ tape)}
346 ^- tank
347 ?: ?=(@ aug)
348 [%leaf (vel aug)]
349 :+ %rose
350 [[' ' ~] ['[' ~] [']' ~]]
351 => .(aug `*`aug)
352 |- ^- (list tank)
353 ?: ?=(@ aug)
354 [^$ ~]
355 [^$(aug -.aug) $(aug +.aug)]
356 ::
357```
360XX document
364---