Scalar extension: Difference between revisions

Jump to navigation Jump to search
m
→‎Singleton extension: HOPL 4 paper has a nice table of conformability support
m (Text replacement - "</source>" to "</syntaxhighlight>")
m (→‎Singleton extension: HOPL 4 paper has a nice table of conformability support)
 
(2 intermediate revisions by the same user not shown)
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, [[APL2]] and specification [[ISO/IEC_13751:2001]] only extend a one-element vector and not any singleton,<ref>[[Roger Hui]] and [[Morten Kromberg]]. [https://dl.acm.org/doi/abs/10.1145/3386319 ''APL since 1978'']. ACM HOPL IV. 2020-06. §2.1 Tally.</ref> 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.
Line 115: Line 116:
└─────────┴─────────┴─────────┘
└─────────┴─────────┴─────────┘
</syntaxhighlight>
</syntaxhighlight>
== References ==
<references/>
{{APL features}}[[Category:Function characteristics]][[Category:Conformability]]
{{APL features}}[[Category:Function characteristics]][[Category:Conformability]]

Navigation menu