Displaying the shape of an array (1 of 9)

Most APLs have a DISPLAY function which may be used to show the rank, shape and depth of an array. For most APLs it's provided as a function DISPLAY. In GNU APL, arrays are displayed using 8⎕CR (or other variants of ⎕CR).

DISPLAY or ⎕DISPLAY takes the data or expression whose value is to be examined as a right argument. For example:

     ⎕DISPLAY 1 2 3
┌→────┐
│1 2 3│
└~────┘

The output from DISPLAY shows the data with boxes around it. The output can have one or many boxes inside the perimeter box. Also you will see that the characters at the left hand end of the top and bottom lines and those at the top of the left side line will change for different data types. It is these boxes and their embedded characters which inform you of the specific structure of the data being examined. Here is a summary of the special characters and their meanings:

Placement on box

Meaning

-

Beneath a character

Scalar character

Left of top edge

Vector or higher-rank array

~

Left of bottom edge

Numeric data

+

Left of bottom edge

Mixed data

Left of top edge

Empty vector or higher-rank array

Left side of box

Matrix or higher-rank array

Left side of box

Empty matrix or higher-rank array

Left of bottom edge

Nested array

The symbols indicate the type of variable contained within the box while the number of boxes within boxes shows the depth of the data. Here are some simple examples:

     ⎕DISPLAY 3 7 8
┌→────┐
│3 7 8│
└~────┘

This first example is a simple 1 dimensional vector. This is indicated by the absence of an arrow on the left hand side of the box showing that there is no organisation along this axis, only along the horizontal axis as shown by the right pointing arrow at the top of the box. The ~ symbol at the bottom of the box indicates numeric data.

     ⎕DISPLAY 3 4⍴⎕A
┌→───┐
↓ABCD│
│EFGH│
│IJKL│
└────┘

This second example shows a two dimensional (rank 2) character matrix. The right arrow and the down arrow indicate two dimensions, while the absence of the ~ character indicates text or character elements.

     ⎕DISPLAY 1 'A' (2 3) (2 5⍴'HELLOWORLD')
┌→──────────────────┐
│     ┌→──┐ ┌→────┐ │
│ 1 A │2 3│ ↓HELLO│ │
│   - └~──┘ │WORLD│ │
│           └─────┘ │
└∊──────────────────┘

The example above shows a nested vector as indicated by and in the outer box. The first two elements are scalars. A scalar character is underlined, whilst a scalar number is not formatted at all. The third element is a numeric vector, and the last is a character matrix.

Where an array is empty, this is shown by the character on the left side of the box or the character on the top side, and the prototype of the array is shown inside the box.


CategoryAboutApl

LearnMoreApl/Display (last edited 2017-02-16 18:48:44 by KaiJaeger)