4c: Tank Printer

    ++re

    Pretty-printing engine

    Pretty-printing engine that accepts a ++tank sample and contains arms that perform computation on it.

    Accepts

    tac is a ++tank.

    Produces

        ++  re
          |_  tac/tank
    

    Examples

        > ~(. re leaf+"ham")
        <2.gdc {tac/{$leaf ""} <402.arm 110.jyx 1.ztu $151>}>
    

    ++ram:re

    Flatten to tape

    Flatten ++tank out into a ++tape.

    Accepts

    tac is a ++tank, taken from sample of ++re core.

    Produces

    A ++tape.

    Source

          ++  ram
            ^-  tape
            ?-    -.tac
                $leaf  p.tac
                $palm  ram(tac [%rose [p.p.tac (weld q.p.tac r.p.tac) s.p.tac] q.tac])
                $rose
              %+  weld
                q.p.tac
              |-  ^-  tape
              ?~  q.tac
                r.p.tac
              =+  voz=$(q.tac t.q.tac)
              (weld ram(tac i.q.tac) ?~(t.q.tac voz (weld p.p.tac voz)))
            ==
          ::
    

    Examples

        > ~(ram re leaf+"foo")
        "foo"
        > ~(ram re rose+["." "(" ")"]^~[leaf+"bar" leaf+"baz" leaf+"bam"])
        "(bar.baz.bam)"
    

    ++win:re

    Render at indent

    Render at indent level tab and width edg.

    Accepts

    tac is a ++tank, taken from sample of ++re core.

    tab and edg are atoms.

    Produces

    A ++wall (++list of ++tapes).

    Source

          ++  win
            |=  {tab/@ edg/@}
            =+  lug=`wall`~
            |^  |-  ^-  wall
                ?-    -.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)
                ::
    

    Examples

        > (~(win re leaf+"samoltekon-lapdok") 0 20)
        <<"samoltekon-lapdok">>
    
        > (~(win re leaf+"samoltekon-lapdok") 0 10)
        <<"\/samolt\/" "  ekon-l" "  apdok" "\/      \/">>
    
        > (~(win re rose+["--" "[" "]"]^~[leaf+"1423" leaf+"2316"]) 0 20)
        <<"[1423--2316]">>
    
        > (~(win re rose+["--" "[" "]"]^~[leaf+"1423" leaf+"2316"]) 0 10)
        <<"[ 1423" "  2316" "]">>
    

    ++din:re

    XX document

    Accepts

    Produces

    Source

        ++  din  (mod (add 2 tab) (mul 2 (div edg 3)))
    

    ++fit:re

    Fit on one line test

    Determine whether tac fits on one line. Internal to ++win

    Accepts

    Produces

    Source

    ++ fit (lte (lent ram) (sub edg tab))

    Examples


    ++rig:re

    Wrap in /

    Wrap ++tape in / if it doesn't fit at current indentation. Internal to ++win

    Accepts

    tac is a ++tank, taken from sample of ++re core.

    hom is a ++tape.

    Produces

    A ++wall (list of ++tapes).

    Source

            ++  rig
              |=  hom/tape
              ^-  wall
              ?:  & ::(lte (lent hom) (sub edg tab))
                [(runt [tab ' '] hom) lug]
              =>  .(tab (add tab 2), edg (sub edg 2))
              =+  mut=(trim (sub edg tab) hom)
              :-  (runt [(sub tab 2) ' '] ['\\' '/' (weld p.mut `_hom`['\\' '/' ~])])
              =>  .(hom q.mut)
              |-
              ?~  hom
                :-  %+  runt
                      [(sub tab 2) ' ']
                    ['\\' '/' (runt [(sub edg tab) ' '] ['\\' '/' ~])]
                lug
              =>  .(mut (trim (sub edg tab) hom))
              [(runt [tab ' '] p.mut) $(hom q.mut)]
            ::
    

    Examples


    ++wig:re

    ++win render tape

    Render ++tape. Internal to ++win.

    Accepts

    tac is a ++tank, taken from sample of ++re core.

    hom is a ++tape.

    Produces

            ++  wig
              |=  hom/tape
              ^-  wall
              ?~  lug
                (rig hom)
              =+  lin=(lent hom)
              =+  wug=:(add 1 tab lin)
              ?.  =+  mir=i.lug
                  |-  ?~  mir
                        |
                      ?|(=(0 wug) ?&(=(' ' i.mir) $(mir t.mir, wug (dec wug))))
                (rig hom)       :: ^ XX regular form?
              [(runt [tab ' '] (weld hom `tape`[' ' (slag wug i.lug)])) t.lug]
            --
          --
    

    ++show

        ++  show                            ::  XX deprecated, use span
          |=  vem/*
          |^  ^-  tank
              ?:  ?=(@ vem)
                [%leaf (mesc (trip vem))]
              ?-    vem
                  {s/$~ c/*}
                [%leaf '\'' (weld (mesc (tape +.vem)) `tape`['\'' ~])]
              ::
                  {s/$a c/@}        [%leaf (mesc (trip c.vem))]
                  {s/$b c/*}        (shop c.vem |=(a/@ ~(rub at a)))
                  {s/{$c p/@} c/*}
                :+  %palm
                  [['.' ~] ['-' ~] ~ ~]
                [[%leaf (mesc (trip p.s.vem))] $(vem c.vem) ~]
              ::
                  {s/$d c/*}        (shop c.vem |=(a/@ ~(rud at a)))
                  {s/$k c/*}        (tank c.vem)
                  {s/$h c/*}
                :+  %rose
                  [['/' ~] ['/' ~] ~]
                =+  yol=((list @ta) c.vem)
                (turn yol |=(a/@ta [%leaf (trip a)]))
              ::
                  {s/$l c/*}        (shol c.vem)
                  {s/$o c/*}
                %=    $
                    vem
                  :-  [%m '%h:<[%d %d].[%d %d]>']
                  [-.c.vem +<-.c.vem +<+.c.vem +>-.c.vem +>+.c.vem ~]
                ==
              ::
                  {s/$p c/*}        (shop c.vem |=(a/@ ~(rup at a)))
                  {s/$q c/*}        (shop c.vem |=(a/@ ~(r at a)))
                  {s/$r c/*}        $(vem [[%r ' ' '{' '}'] c.vem])
                  {s/$t c/*}        (shop c.vem |=(a/@ ~(rt at a)))
                  {s/$v c/*}        (shop c.vem |=(a/@ ~(ruv at a)))
                  {s/$x c/*}        (shop c.vem |=(a/@ ~(rux at a)))
                  {s/{$m p/@} c/*}  (shep p.s.vem c.vem)
                  {s/{$r p/@} c/*}
                $(vem [[%r ' ' (cut 3 [0 1] p.s.vem) (cut 3 [1 1] p.s.vem)] c.vem])
              ::
                  {s/{$r p/@ q/@ r/@} c/*}
                :+  %rose
                  :*  p=(mesc (trip p.s.vem))
                      q=(mesc (trip q.s.vem))
                      r=(mesc (trip r.s.vem))
                  ==
                |-  ^-  (list tank)
                ?@  c.vem
                  ~
                [^$(vem -.c.vem) $(c.vem +.c.vem)]
              ::
                  {s/$z c/*}        $(vem [[%r %$ %$ %$] c.vem])
                  *                 !!
              ==
    

    XX document

    ++shep

          ++  shep
            |=  {fom/@ gar/*}
            ^-  tank
            =+  l=(met 3 fom)
            =+  i=0
            :-  %leaf
            |-  ^-  tape
            ?:  (gte i l)
              ~
            =+  c=(cut 3 [i 1] fom)
            ?.  =(37 c)
              (weld (mesc [c ~]) $(i +(i)))
            =+  d=(cut 3 [+(i) 1] fom)
            ?.  .?(gar)
              ['\\' '#' $(i (add 2 i))]
            (weld ~(ram re (show d -.gar)) $(i (add 2 i), gar +.gar))
          ::
    

    XX document

    ++shop

         ++  shop
            |=  {aug/* vel/$-(a/@ tape)}
            ^-  tank
            ?:  ?=(@ aug)
              [%leaf (vel aug)]
            :+  %rose
              [[' ' ~] ['[' ~] [']' ~]]
            =>  .(aug `*`aug)
            |-  ^-  (list tank)
            ?:  ?=(@ aug)
              [^$ ~]
            [^$(aug -.aug) $(aug +.aug)]
          ::
    

    XX document