displays←{⎕IO ⎕ML←0 1                                 ⍝ Boxed display of array.
    box←{                                             ⍝ Box with type and axes.
        shp wopen\⍵
        vrt hrz(¯1+⍴w)⍴¨'│─'                         ⍝ Vert. and horiz. lines.
        top('─⊖→')[¯1↑⍺],hrz                         ⍝ Upper border with axis.
        ok(shp)<⍴hrz
        top(top)(2↑top),(ok/shp),(2+ok×⍴shp)top
        bot(⊃⍺),hrz                                  ⍝ Lower border with type.
        rgt←'┐│',vrt,'┘'                              ⍝ Right side with corners.
        lax('│⌽↓')[¯1↓1↓⍺],¨⊂vrt                     ⍝ Left side(s) with axes,
        lft←⍉'┌',(lax),'└'                           ⍝ ... and corners.
        lft,(topwbot),rgt                           ⍝ Fully boxed array.
    }
    deco←{⍺←type open ⍵ ⋄ ⍺,axes ⍵}                   ⍝ Type and axes vector.
    axes←{(-2⌈⍴⍴⍵)↑1+×⍴⍵}                             ⍝ Array axis types.
    open←{(1⌈⍴⍵)⍴⍵}                                   ⍝ Expose null axes.
    trim←{(0⊃⍵)((~1 1⍷∧⌿(1⊃⍵)=' ')/(1⊃⍵))}            ⍝ Remove extra blank cols.
    type←{{(1=⍴⍵)⊃'+'⍵}∪,char¨⍵}                      ⍝ Simple array type.
    char←{⍬≡⍴⍵:'─' ⋄ (⊃⍵∊'¯',⎕D)⊃'#~'}∘⍕              ⍝ Simple scalar type.
    qfmt←{(⍕⍴⍺)(⎕FMT open)}
    {                                                 ⍝ Recursively box arrays:
        0=≡⍵:' '⍪(⎕FMT ⍵)(' '≡⊃0⍴⍵)⊃' -'             ⍝ Simple scalar.
        1 ⍬≡(≡⍵)(⍴⍵):'∇' 0 0 box(,'─')(⎕FMT ⍵)        ⍝ Object rep: ⎕OR.
        1=≡⍵:(deco)box openqfmt ⍵                ⍝ Simple array.
        ('∊'deco)box trimqfmt ∇¨open ⍵           ⍝ Nested array.
    }⍵
}
code_colours

test script

Back to: notes

Back to: Workspaces