Prototype: Difference between revisions

Jump to navigation Jump to search
269 bytes added ,  15:53, 13 November 2019
no edit summary
Miraheze>Adám Brudzewsky
No edit summary
Miraheze>Adám Brudzewsky
No edit summary
Line 1: Line 1:
{{Built-ins|Prototype|∊|⊤}} is a [[monadic function]] which in the [[nested array model]] gives information about the type and structure of its argument array's [[element]]s. The result is derived from the first element of the array in [[ravel order]], or, if the array is [[Empty array|empty]], from information stored alongside the array (usually this information is just the prototype itself). An array's prototype is used as a [[fill element]] for operations involving that array, and to determine some [[identity element]]s.
The '''prototype''' of an array is, in the [[nested array model]], an array which gives information about the type and structure of its [[element]]s. It is derived from the first element of the array in [[ravel order]], or, if the array is [[Empty array|empty]], from information stored alongside the array (usually this information is just the prototype itself). An array's prototype is used as a [[fill element]] for operations involving that array, and to determine some [[identity element]]s.


== Support==
== Support ==
Few dialects have Prototype as a [[primitive function]]. [[Dyalog APL]] uses <source lang=apl inline></source> (as in ''prototypical '''e'''lement''), but only when [[migration level]] is 0, while [[NARS2000]] uses [[monadic]] <source lang=apl inline></source> (resembling the Latin letter '''T''' for '''''T'''ype'').
A few dialects have [[Type]] as a [[primitive function]], and in those, the prototype is simply the type of the first element:
 
<source lang=apl>
However, an arrays prototype can always be determined by enclosing the array in an empty array, and then coercing our a fill value. Since prototypes are used as fill elements, the resulting array will be the prototype of the original array:
      ∊⊃ 1 2 'ab'
┌─┬─┬──┐
│0│0│  │
└─┴─┴──┘
</source>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>0}}
<source lang=apl>
      ⊤↑ 1 2 'ab'
┌─┬─┬──┐
│0│0│  │
└─┴─┴──┘
</source>
{{Works in|[[NARS2000]]}}
However, an array's prototype can always be determined by enclosing the first element in an empty array, and then coercing out a fill value:
<source lang=apl>
      ⊃ 0 ⍴ ⊂ 1 2 'ab'
┌─┬─┬──┐
│0│0│  │
└─┴─┴──┘
</source>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}}
<source lang=apl>
<source lang=apl>
       ⊃ 0 ⍴ ⊂ 1 2 'ab'
       ⊃ 0 ⍴ ⊂ 1 2 'ab'
Line 11: Line 31:
└─┴─┴──┘
└─┴─┴──┘
</source>
</source>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>≥</nowiki>2, [[APL2]], [[APLX]]}}


APLs with a [[flat array model]] do not typically store prototype information, instead using only the array's type ([[character]], [[numeric]], or [[Box|boxed]]) to determine its [[Fill element|fills]].
APLs with a [[flat array model]] do not typically store prototype information, instead using only the array's type ([[character]], [[numeric]], or [[Box|boxed]]) to determine its [[Fill element|fills]].
Line 68: Line 89:
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
{{APL programming language}}
{{APL programming language}}
{{APL built-ins}}

Navigation menu