Array model: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
mNo edit summary
Miraheze>Adám Brudzewsky
No edit summary
Line 9: Line 9:
Parentheses are used to group array items.
Parentheses are used to group array items.


Numbers are very straight forward: a number is a number. It doesn't matter if it is an integer or not, nor if it is real or complex. Negative numbers are denoted by a 'high minus': <code>¯</code>. You can also use scientific notation with <code>e</code> (or <code>E</code>), so a million is <code>1E6</code>
Numbers are very straight forward: a number is a number. It doesn't matter if it is an integer or not, nor if it is real or complex. Negative numbers are denoted by a ''high minus'': <code>¯</code>. You can also use scientific notation with <code>e</code> (or <code>E</code>), so a million is <code>1E6</code>


The items of an array can be of different types.
The items of an array can be of different types.

Revision as of 20:43, 18 September 2019

APL uses a uniquely versatile array model, much more powerful than the linked lists of many traditional programming languages like Python and JavaScript.

All data in APL resides in arrays. An array is a rectangular collection of numbers, characters and arrays, arranged along zero or more axes. Numbers and characters are 0 dimensional arrays, and are referred to as scalars. Characters are in single quotes.

Creating a 1-dimensional array is very simple: just write the elements next to each other, separated by spaces. This syntax works for any data that you want in the array: numbers, characters, other arrays (etc.)

A string is just a character vector, which may be written with single quotes around the entire string.

Parentheses are used to group array items.

Numbers are very straight forward: a number is a number. It doesn't matter if it is an integer or not, nor if it is real or complex. Negative numbers are denoted by a high minus: ¯. You can also use scientific notation with e (or E), so a million is 1E6

The items of an array can be of different types.

An array has a rank and a depth.

Depth

Main article: Depth

The depth is the level of nesting. For example an array of simple (i.e. non-nested) scalars has depth 1, an array containing only depth 1 arrays has depth 2 and a simple scalar (e.g a number or character) has depth 0. However, for some arrays it's not so easy. An array may contain both vectors and scalars. In cases like this, the depth is reported as negative. You can find the depth of an array with the function .

Rank

Main article: Rank

The concept of rank is very important in APL, and isn't present in many other languages. It refers to the number of dimensions in the array. So far, rank-0 arrays are scalars, rank-1 arrays are vectors, rank-2 arrays are usually called matrices or tables.

External links

Formal definition

Chat lesson

Vector notation