cmat ← {dec←1 {box←1 {cen←1}}} ##.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:

    ┌───── dec: type and shape decoration:· · on        (otherwise, off)
    │ ┌─── box: box-drawing chars:· · · · · · smooth    (otherwise, clunky)
    │ │ ┌─ cen: 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)('Gals' 20 80)
┌────┬────────┬───────┐
│ %  │Eye Poke│Kumquat│
├────┼────────┼───────┤
│Guys│   60   │  40   │
├────┼────────┼───────┤
│Gals│   20   │  80   │
└────┴────────┴───────┘

⍝ The following shows the effect of various left-argument options:
⍝
⍝   dec: type and shape decorations off/on,
⍝       box: smooth borders off/on,
⍝           cen: centre-alignment within box off/on.

    opts← ⎕io≠⍳2 2 2                ⍝ all combinations of left-argument options.

    r c s←(1 7)(3 1)(1 1)⍴¨' '      ⍝ row, column and single matrices.

    {⍵ disp 2 2⍴⍵ c r s}¨ opts      ⍝ display format by option.
 .-------.-.  .-------.-.
 |0 0 0  | |  |       | |
 |       | |  | 0 0 1 | |
 |       | |  |       | |
 |-------+-|  |-------+-|
 |       | |  |       | |
 '-------'-'  '-------'-'
 ┌───────┬─┐  ┌───────┬─┐
 │0 1 0  │ │  │       │ │
 │       │ │  │ 0 1 1 │ │
 │       │ │  │       │ │
 ├───────┼─┤  ├───────┼─┤
 │       │ │  │       │ │
 └───────┴─┘  └───────┴─┘

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

See also: display box

Back to: contents

Back to: Workspaces

Trouble seeing APL font?