Singleton: Difference between revisions
No edit summary |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 1: | Line 1: | ||
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: | 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]] < | * The [[scalar]] <syntaxhighlight lang=apl inline>42</source> | ||
* The [[vector]] < | * The [[vector]] <syntaxhighlight lang=apl inline>,42</source> | ||
* The [[matrix]] < | * The [[matrix]] <syntaxhighlight lang=apl inline>⍪42</source> | ||
* The three-[[dimension]]al array < | * The three-[[dimension]]al array <syntaxhighlight lang=apl inline>1 1 1⍴42</source> | ||
* The [[nested]] scalar < | * The [[nested]] scalar <syntaxhighlight lang=apl inline>⊂4 2</source> | ||
Whether an array < | Whether an array <syntaxhighlight lang=apl inline>X</source> is a singleton can be determined with <syntaxhighlight lang=apl inline>1=×/⍴X</source> or, less efficiently, with <syntaxhighlight lang=apl inline>1=≢,X</source>. | ||
Every scalar < | Every scalar <syntaxhighlight lang=apl inline>X</source> is a singleton, because <syntaxhighlight lang=apl inline>1=×/⍴X</source>, or alternatively <syntaxhighlight lang=apl inline>1=≢,X</source>. | ||
Singletons may be subject to [[singleton extension]]. | Singletons may be subject to [[singleton extension]]. |
Revision as of 10:50, 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:
- The scalar <syntaxhighlight lang=apl inline>42</source>
- The vector <syntaxhighlight lang=apl inline>,42</source>
- The matrix <syntaxhighlight lang=apl inline>⍪42</source>
- The three-dimensional array <syntaxhighlight lang=apl inline>1 1 1⍴42</source>
- The nested scalar <syntaxhighlight lang=apl inline>⊂4 2</source>
Whether an array <syntaxhighlight lang=apl inline>X</source> is a singleton can be determined with <syntaxhighlight lang=apl inline>1=×/⍴X</source> or, less efficiently, with <syntaxhighlight lang=apl inline>1=≢,X</source>.
Every scalar <syntaxhighlight lang=apl inline>X</source> is a singleton, because <syntaxhighlight lang=apl inline>1=×/⍴X</source>, or alternatively <syntaxhighlight lang=apl inline>1=≢,X</source>.
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 | 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 ∙ Function array |
Concepts and paradigms | Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity element ∙ Complex floor ∙ Array ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ Glyph ∙ Leading axis theory ∙ Major cell search ∙ First-class function |
Errors | LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR ∙ EVOLUTION ERROR |