cmat ← {deco} ##.disp array                 ⍝ Boxed sketch of nested array.

A  compact alternative to the →display← function for nested arrays. The shape of
the  containing  array  is shown in its top-left corner. For each subarray, item
type is shown lower-left and shape is shown lower-right.

Although  in  general,  all  the  information  provided by →display← is present,
arrays  of  rank>3  are  not  distinguished,  and the type (~) of a single digit
number may be obscured by its shape (─/→) decoration. 

The optional left argument of 1, 2 or 3 boolean flags (default 1 1 1) controls:

    ┌─────type and shape decoration:· · on          (otherwise, off)
    │ ┌───box-drawing chars:· · · · · · smooth      (otherwise, clunky)
    │ │ ┌─items within boxes aligned: · centred     (otherwise, top-left)
    │ │ │
    1 1 1 disp ..

With decoration turned off (0 disp ..) the function can be used to format simple
tables for display in the session; see example below.

Examples:

      disp 2 2⍴'Tea'(2 1⍴4 2)'&'(2 40)          ⍝ [disp] form of nested array.
┌→──┬────┐ 
↓Tea│ 4  │
│   │ 2  ↓
├──→┼~──→┤ 
│ & │2 40│
└───┴~──→┘ 

      display 2 2⍴'Tea'(2 1⍴4 2)'&'(2 40)       ⍝ Compare with [display] form.
┌→─────────────┐ 
↓ ┌→──┐ ┌→┐    │ 
│ │Tea│ ↓4│    │
│ └───┘ │2│    │
│       └~┘    │
│       ┌→───┐ │ 
│ &     │2 40│ │
│ -     └~───┘ │
└∊─────────────┘

      disp array                                ⍝ [disp] sketch of array.
┌→──┬─────────┬─────────┬────────┐ 
↓3.1│ Vector  │ Matrix  ↓ Array  ⍒
├~──┼────────→┼────────→┼───────→┤ 
│┌─┐│┌→──┬───┐│┌→──┬───┐│┌→─────┐│ 
││0│││Q 8│K 9││⌽0 0│0 0││⍒ #  # ││
│└⊖┘│└+─→┴+─→┘│└~─→┴~─→┘⌽└#────→┘⍒ 
└───┴────────→┴────────→┴───────→┘ 

      display array                             ⍝ Compare with full [display].
┌→──────────────────────────────────────────────────────┐ 
↓         ┌→─────┐        ┌→─────┐        ┌┌→────┐      │ 
│ 3.1     │Vector│        ↓Matrix│        ↓↓Array│      │
│         └──────┘        └──────┘        └└─────┘      │
│ ┌─────┐ ┌→────────────┐ ┌→────────────┐ ┌┌→─────────┐ │ 
│ │ ┌⊖┐ │ │ ┌→──┐ ┌→──┐ │ ⌽ ┌→──┐ ┌→──┐ │ ↓↓ ┌→─────┐ │ │ 
│ │ │0│ │ │ │Q 8│ │K 9│ │ │ │0 0│ │0 0│ │ ││ │ #  # │ │ │
│ │ └~┘ │ │ └+──┘ └+──┘ │ │ └~──┘ └~──┘ │ ││ └#─────┘ │ │
│ └∊────┘ └∊────────────┘ └∊────────────┘ └└∊─────────┘ │
└∊──────────────────────────────────────────────────────┘

                        ⍝ Simple table in session:

      0 disp'%' 'Eye Poke' 'Kumquat'⍪↑('Guys' 60 40)('Dolls' 20 80)
┌─────┬────────┬───────┐
│  %  │Eye Poke│Kumquat│
├─────┼────────┼───────┤
│Guys │   60   │  40   │
├─────┼────────┼───────┤
│Dolls│   20   │  80   │
└─────┴────────┴───────┘

      opts←0 1∘.,0 1    ⍝ Display options: decoration ∘.vs box_chars

      opts disp¨ ⊂opts
 .---.---.  ┌───┬───┐
 |0 0|0 1|  │0 0│0 1│
 |---+---|  ├───┼───┤
 |1 0|1 1|  │1 0│1 1│
 '---'---'  └───┴───┘
 .→--.---.  ┌→──┬───┐ 
 ↓0 0|0 1|  ↓0 0│0 1│
 |~-→+~-→|  ├~─→┼~─→┤ 
 |1 0|1 1|  │1 0│1 1│
 '~-→'~-→'  └~─→┴~─→┘ 

    mat ← 2 2⍴(1 1)(3 1)(1 3)(1 1)⍴¨'⍟...'      ⍝ nested matrix.

    0 1 1 disp mat                              ⍝ items centred.
┌───┬─┐
│   │.│
│ ⍟ │.│
│   │.│
├───┼─┤
│...│.│
└───┴─┘

    0 1 0 disp mat                              ⍝ items top-left aligned.
┌───┬─┐
│⍟  │.│
│   │.│
│   │.│
├───┼─┤
│...│.│
└───┴─┘

See also: display box

Back to: contents

Back to: Dyalog APL

Trouble seeing APL font?