Array model
APL uses a uniquely versatile array model, much more powerful than the [linked lists](https://en.wikipedia.org/wiki/Linked_list) 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
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
[http://help.dyalog.com/latest/Content/Language/Introduction/Variables/Arrays.htm Formal definition)
[https://chat.stackexchange.com/rooms/52405/conversation/lesson-1-introduction-to-arrays-in-apl Chat lesson)
[http://help.dyalog.com/latest/Content/Language/Introduction/Variables/Vector%20Notation.htm Vector notation)