hoon: refactors |re for clarity

This commit is contained in:
Joe Bryan 2020-05-12 13:23:45 -07:00
parent c9db96382a
commit 25cea09fd1

View File

@ -4929,82 +4929,129 @@
?~ kids (cat 3 '(' (cat 3 sym ')')) ?~ kids (cat 3 '(' (cat 3 sym ')'))
[%sbrk [%tree fmt kids]] [%sbrk [%tree fmt kids]]
:: ::
:: |re: tank renderer
::
++ re ++ re
|_ tac/tank |_ tac=tank
:: +ram: render a tank to one line (flat)
::
++ ram ++ ram
^- tape ^- tape
?- -.tac ?- -.tac
$leaf p.tac %leaf p.tac
$palm ram(tac [%rose [p.p.tac (weld q.p.tac r.p.tac) s.p.tac] q.tac]) ::
$rose :: flat %palm rendered as %rose with welded openers
::
%palm
=* mid p.p.tac
=* for (weld q.p.tac r.p.tac)
=* end s.p.tac
ram(tac [%rose [mid for end] q.tac])
::
:: flat %rose rendered with open/mid/close
::
%rose
=* mid p.p.tac
=* for q.p.tac
=* end r.p.tac
=* lit q.tac
%+ weld %+ weld
q.p.tac for
|- ^- tape |- ^- tape
?~ q.tac ?~ lit
r.p.tac end
=+ voz=$(q.tac t.q.tac) %+ weld
(weld ram(tac i.q.tac) ?~(t.q.tac voz (weld p.p.tac voz))) ram(tac i.lit)
=* voz $(lit t.lit)
?~(t.lit voz (weld mid voz))
== ==
:: +win: render a tank to multiple lines (tall)
::
:: indented by .tab, soft-wrapped at .edg
:: ::
++ win ++ win
|= {tab/@ edg/@} |= [tab=@ud edg=@ud]
=+ lug=`wall`~ :: output stack
|^ |- ^- wall ::
=| lug=wall
|^ ^- wall
?- -.tac ?- -.tac
$leaf (rig p.tac) %leaf (rig p.tac)
$palm
?: fit
(rig ram)
?~ q.tac
(rig q.p.tac)
?~ t.q.tac
(rig(tab (add 2 tab), lug $(tac i.q.tac)) q.p.tac)
=> .(q.tac `(list tank)`q.tac)
=+ lyn=(mul 2 (lent q.tac))
=+ ^= qyr
|- ^- wall
?~ q.tac
lug
%= ^$
tac i.q.tac
tab (add tab (sub lyn 2))
lug $(q.tac t.q.tac, lyn (sub lyn 2))
==
(wig(lug qyr) q.p.tac)
:: ::
$rose %palm
?: fit =/ hom ram
(rig ram) ?: (lte (lent hom) (sub edg tab))
(rig hom)
::
=* for q.p.tac
=* lit q.tac
?~ lit
(rig for)
?~ t.lit
=: tab (add 2 tab)
lug $(tac i.lit)
==
(rig for)
::
=> .(lit `(list tank)`lit)
=/ lyn (mul 2 (lent lit))
=. lug =. lug
|- ^- wall |- ^- wall
?~ q.tac ?~ lit
?:(=(~ r.p.tac) lug (rig r.p.tac)) lug
^$(tac i.q.tac, lug $(q.tac t.q.tac), tab din) =/ nyl (sub lyn 2)
?: =(~ q.p.tac) %= ^$
lug tac i.lit
(wig q.p.tac) tab (add tab nyl)
lug $(lit t.lit, lyn nyl)
==
(wig for)
::
%rose
=/ hom ram
?: (lte (lent hom) (sub edg tab))
(rig hom)
::
=* for q.p.tac
=* end r.p.tac
=* lit q.tac
=. lug
|- ^- wall
?~ lit
?~(end lug (rig end))
%= ^$
tac i.lit
tab (mod (add 2 tab) (mul 2 (div edg 3)))
lug $(lit t.lit)
==
?~(for lug (wig for))
== ==
:: +rig: indent tape and cons with output stack
:: ::
++ din (mod (add 2 tab) (mul 2 (div edg 3)))
++ fit (lte (lent ram) (sub edg tab))
++ rig ++ rig
|= hom/tape |= hom=tape
^- wall ^- wall
[(runt [tab ' '] hom) lug] [(runt [tab ' '] hom) lug]
:: +wig: indent tape and cons with output stack
::
:: joined with the top line if whitespace/indentation allow
:: ::
++ wig ++ wig
|= hom/tape |= hom=tape
^- wall ^- wall
?~ lug ?~ lug
(rig hom) (rig hom)
=+ lin=(lent hom) =/ wug :(add 1 tab (lent hom))
=+ wug=:(add 1 tab lin)
?. =+ mir=i.lug ?. =+ mir=i.lug
|- ?~ mir |- ^- ?
| ?~ mir |
?|(=(0 wug) ?&(=(' ' i.mir) $(mir t.mir, wug (dec wug)))) ?| =(0 wug)
?&(=(' ' i.mir) $(mir t.mir, wug (dec wug)))
==
(rig hom) :: ^ XX regular form? (rig hom) :: ^ XX regular form?
[(runt [tab ' '] (weld hom `tape`[' ' (slag wug i.lug)])) t.lug] :_ t.lug
%+ runt [tab ' ']
(weld hom `tape`[' ' (slag wug i.lug)])
-- --
-- --
++ show :: XX deprecated! ++ show :: XX deprecated!