Scalar

From APL Wiki
Revision as of 21:27, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search

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 x.

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.

External Links

Is a scalar an array?

APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR