In the APL array model, a scalar is an array with rank zero, that is, empty shape. A scalar contains only a single element: its bound is the product of the empty list
×/⍬, or 1. The Enclose function creates scalars: for any array
x, its enclose
⊂x is a scalar whose only element is
In a language using nested lists for arrays, there is one level of nesting for each axis, so a "scalar" would have zero levels: it is not a list. In APL a scalar is considered an array, and a scalar containing an array is usually distinct from that array.
Scalar extension is the process of extending a function to accept a scalar when an array of a specific shape would normally be expected. Since the scalar has only one element, there is only one possibility: the scalar is treated as an array all of whose elements are that element.
The floating array model identifies the enclose of a simple scalar (that is, a scalar array containing a simple scalar) with the scalar itself. However, the enclose of a non-simple scalar, such as an enclosed matrix, is still distinct from its element.
Under a strict definition a scalar has no major cells, since a major cell of a rank 0 array would have rank ¯1, which is impossible. A common convention in array langauges such as Dyalog APL and J which define functions in terms of major cells is that a scalar has a single major cell—itself. Thus
≢'a' is equal to 1. Similarly, it is common for functions or operators which act on the axes of an array to act as though the array has an invisible axis of length 1. Reversing or reducing a scalar yields that scalar with no changes.
Iverson's A Dictionary of APL uses the name "item" for scalars.
|APL features |
|Built-ins||Primitives (functions, operators) ∙ Quad name|
|Array model||Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index (Indexing) ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype|
|Data types||Number (Boolean, Complex number) ∙ Character (String) ∙ Box ∙ Namespace|
|Concepts and paradigms||Leading axis theory ∙ Scalar extension ∙ Conformability ∙ Leading axis agreement ∙ Scalar function ∙ Pervasion ∙ Glyph ∙ Identity element ∙ Complex floor ∙ Total array ordering|
|Errors||LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR|