Singleton: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Kinds of array category)
m (Text replacement - "</source>" to "</syntaxhighlight>")
Tags: Mobile edit Mobile web edit
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A '''singleton''' is an [[array]] with [[bound]] 1. Equivalently, its [[shape]] consists entirely of 1s. It may have any [[rank]]. For example, all the following are singletons:
A '''singleton''' is an [[Array model|array]] with [[bound]] 1. Equivalently, its [[shape]] consists entirely of 1s. It may have any [[rank]]. For example, all the following are singletons:


* The [[scalar]] <source lang=apl inline>42</source>
* The [[scalar]] <syntaxhighlight lang=apl inline>42</syntaxhighlight>
* The [[vector]] <source lang=apl inline>,42</source>
* The [[vector]] <syntaxhighlight lang=apl inline>,42</syntaxhighlight>
* The [[matrix]] <source lang=apl inline>⍪42</source>
* The [[matrix]] <syntaxhighlight lang=apl inline>⍪42</syntaxhighlight>
* The three-[[dimension]]al array <source lang=apl inline>1 1 1⍴42</source>
* The three-[[dimension]]al array <syntaxhighlight lang=apl inline>1 1 1⍴42</syntaxhighlight>
* The [[nested]] scalar <source lang=apl inline>⊂4 2</source>
* The [[nested]] scalar <syntaxhighlight lang=apl inline>⊂4 2</syntaxhighlight>


Whether an array <source lang=apl inline>X</source> is a singleton can be determined with <source lang=apl inline>1=×/⍴X</source> or, less efficiently, with <source lang=apl inline>1=≢,X</source>.
Whether an array <syntaxhighlight lang=apl inline>X</syntaxhighlight> is a singleton can be determined with <syntaxhighlight lang=apl inline>1=×/⍴X</syntaxhighlight> or, less efficiently, with <syntaxhighlight lang=apl inline>1=≢,X</syntaxhighlight>.


Every scalar <source lang=apl inline>X</source> is a singleton, because <source lang=apl inline>1=×/⍴X</source>, or alternatively <source lang=apl inline>1=≢,X</source>.
Every scalar <syntaxhighlight lang=apl inline>X</syntaxhighlight> is a singleton, because <syntaxhighlight lang=apl inline>1=×/⍴X</syntaxhighlight>, or alternatively <syntaxhighlight lang=apl inline>1=≢,X</syntaxhighlight>.


Singletons may be subject to [[singleton extension]].
Singletons may be subject to [[singleton extension]].
Only [[simple]] [[Boolean]] singletons are valid representations of logical true and false for the purposes of [[control structure]]s.
{{APL features}}[[Category:Kinds of array]]
{{APL features}}[[Category:Kinds of array]]

Latest revision as of 11:00, 11 September 2022

A singleton is an array with bound 1. Equivalently, its shape consists entirely of 1s. It may have any rank. For example, all the following are singletons:

Whether an array X is a singleton can be determined with 1=×/⍴X or, less efficiently, with 1=≢,X.

Every scalar X is a singleton, because 1=×/⍴X, or alternatively 1=≢,X.

Singletons may be subject to singleton extension.

Only simple Boolean singletons are valid representations of logical true and false for the purposes of control structures.

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 search
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR