Scalar extension: Difference between revisions

Jump to navigation Jump to search
90 bytes added ,  09:06, 29 October 2019
m
Text replacement - "<code>" to "<source lang=apl inline>"
Miraheze>Adám Brudzewsky
Miraheze>Adám Brudzewsky
m (Text replacement - "<code>" to "<source lang=apl inline>")
Line 3: Line 3:
== History and terminology ==
== History and terminology ==


The concept of scalar extension has been around since [[APL\360]]. An example which extends the scalar <code>2</code> is:
The concept of scalar extension has been around since [[APL\360]]. An example which extends the scalar <source lang=apl inline>2</code> is:
<source lang=apl>
<source lang=apl>
       2 × 1 2 3 4
       2 × 1 2 3 4
Line 12: Line 12:
The word "extension" applies to scalar extension in two ways: first, a function is extended by making a case which would have been a [[RANK ERROR]] into a valid application. Second, the application works by conceptually extending the scalar to function as though it were an array of higher rank.
The word "extension" applies to scalar extension in two ways: first, a function is extended by making a case which would have been a [[RANK ERROR]] into a valid application. Second, the application works by conceptually extending the scalar to function as though it were an array of higher rank.


Two arrays are said to [[Conformability|conform]] if they have the same shape or at least one can be extended (it is a scalar, or, in langauges with singleton extension, has exactly one element). A pair of conforming arrays defines a single shape which describes how their elements are paired: if neither is a scalar, it is their shared shape; if one is a scalar, it is the other's shape; if both are scalars, it is <code>⍬</code>.
Two arrays are said to [[Conformability|conform]] if they have the same shape or at least one can be extended (it is a scalar, or, in langauges with singleton extension, has exactly one element). A pair of conforming arrays defines a single shape which describes how their elements are paired: if neither is a scalar, it is their shared shape; if one is a scalar, it is the other's shape; if both are scalars, it is <source lang=apl inline>⍬</code>.


=== Rank extension ===
=== Rank extension ===


The term "scalar extension" is sometimes used to refer to the practice of allowing a scalar when a higher rank is expected. The scalar is treated as an array of the expected minimum rank whose shape is a vector of 1s (that is, a [[singleton]]). For example, <code>⍳8</code> and <code>8⍴'a'</code> both produce an 8-element array even though the shape of an array is always a vector and so cannot be equal to <code>8</code>. This type of extension, which differs from ordinary scalar extension in that there is no expected shape and only an expected rank, has also been present since [[APL\360]].
The term "scalar extension" is sometimes used to refer to the practice of allowing a scalar when a higher rank is expected. The scalar is treated as an array of the expected minimum rank whose shape is a vector of 1s (that is, a [[singleton]]). For example, <source lang=apl inline>⍳8</code> and <source lang=apl inline>8⍴'a'</code> both produce an 8-element array even though the shape of an array is always a vector and so cannot be equal to <source lang=apl inline>8</code>. This type of extension, which differs from ordinary scalar extension in that there is no expected shape and only an expected rank, has also been present since [[APL\360]].


=== Singleton extension ===
=== Singleton extension ===

Navigation menu