display←{⎕IO ⎕ML←0 1                        ⍝ Boxed display of array.

    box←{                                   ⍝ box with type and axes
        vrt hrz(¯1+⍴⍵)⍴¨'│─'               ⍝ vert. and horiz. lines
        top←'─⊖→'[¯1↑⍺],hrz                 ⍝ upper border with axis
        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,(top⍪⍵⍪bot),rgt                 ⍝ fully boxed array
    }

    deco←{⍺←type open ⍵ ⋄ ⍺,axes ⍵}         ⍝ type and axes vector
    axes←{(-2⌈⍴⍴⍵)↑1+×⍴⍵}                   ⍝ array axis types
    open←{16::(1⌈⍴⍵)⍴⊂'[ref]' ⋄ (1⌈⍴⍵)⍴⍵}   ⍝ exposure of null axes
    trim←{(~1 1⍷∧⌿⍵=' ')/⍵}                 ⍝ removal of extra blank cols
    type←{{(1=⍴⍵)⊃'+'⍵}∪,char¨⍵}            ⍝ simple array type
    char←{⍬≡⍴⍵:'─' ⋄ (⊃⍵∊'¯',⎕D)⊃'#~'}∘⍕    ⍝ simple scalar type
    line←{(6≠10|⎕DR' '⍵)⊃' -'}              ⍝ underline for atom

    {                                       ⍝ recursive boxing of arrays:
        0=≡⍵:' '⍪(open ⎕FMT ⍵)line ⍵       ⍝ simple scalar
        1 ⍬≡(≡⍵)(⍴⍵):'∇' 0 0 box ⎕FMT ⍵     ⍝ object rep: ⎕OR
        1=≡⍵:(deco)box open ⎕FMT open ⍵   ⍝ simple array
        ('∊'deco)box trim ⎕FMT ∇¨open ⍵   ⍝ nested array
    }⍵
}
code_colours

test script

Back to: notes

Back to: Workspaces