Scalar extension: Difference between revisions

Jump to navigation Jump to search
→‎Singleton extension: It's very widely supported: 360, SHARP, A+, Dyalog, etc.
m (Text replacement - "</source>" to "</syntaxhighlight>")
(→‎Singleton extension: It's very widely supported: 360, SHARP, A+, Dyalog, etc.)
Line 20: Line 20:
=== Singleton extension ===
=== Singleton extension ===


Some APLs, such as [[Dyalog APL]], treat arrays with one element ([[singleton]]s) as scalars for the purposes of scalar extension. This practice is referred to as "singleton extension". For example,
Most APLs treat arrays with one element ([[singleton]]s) as scalars for the purposes of scalar extension. While often referred to simply as "scalar extension", this practice could more precisely be called "singleton extension". For example,
<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
       (1 1⍴5) + 10 20
       (1 1⍴5) + 10 20
Line 27: Line 27:
2
2
</syntaxhighlight>
</syntaxhighlight>
{{Works in|[[Dyalog APL]], [[APLX]]}}
In this case addition accepts a singleton, and discards its shape. If two singletons are used as arguments, they are still considered to [[Conformability|conform]]; the shape of the result is taken from the argument with higher rank.
In this case addition accepts a singleton, and discards its shape. If two singletons are used as arguments, they are still considered to [[Conformability|conform]]; the shape of the result is taken from the argument with higher rank.
Singleton extension was supported in [[APL\360]] by 1970<ref>S. Charmonman. [https://dl.acm.org/doi/10.1145/987461.987468 A generalization of APL array-oriented concept]. [[APL Quote Quad]] Volume 2, Number 3. 1970-09.</ref> and is generally present in later APLs. However, [[ISO/IEC_13751:2001]] only specifies extension of a one-element vector and not of any singleton, and some newer dialects such as [[dzaima/APL]] and [[Kap]] don't implement singleton extension.


Singleton extension can sometimes conflict with other extensions, an issue which does not occur with scalar extension. If a function is extended to allow a shorter vector argument to be extended (perhaps by padding with 0), but it also supports singleton extension, then there is a conflict with length-1 vectors.
Singleton extension can sometimes conflict with other extensions, an issue which does not occur with scalar extension. If a function is extended to allow a shorter vector argument to be extended (perhaps by padding with 0), but it also supports singleton extension, then there is a conflict with length-1 vectors.

Navigation menu