Prototype: Difference between revisions

Jump to navigation Jump to search
108 bytes added ,  09:06, 29 October 2019
m
Text replacement - "<code>" to "<source lang=apl inline>"
Miraheze>Adám Brudzewsky
No edit summary
Miraheze>Adám Brudzewsky
m (Text replacement - "<code>" to "<source lang=apl inline>")
Line 5: Line 5:
== Examples ==
== Examples ==


The prototype is used when an array is expanded or when empty elements are inserted in some other way. [[Take]] and [[Expand]] on a [[character]] array produce an array with spaces, because <code>' '</code> is the prototype of a character array:
The prototype is used when an array is expanded or when empty elements are inserted in some other way. [[Take]] and [[Expand]] on a [[character]] array produce an array with spaces, because <source lang=apl inline>' '</code> is the prototype of a character array:
<source lang=apl>
<source lang=apl>
       ¯12 ↑ 'whitespace'
       ¯12 ↑ 'whitespace'
Line 13: Line 13:
</source>
</source>


The [[Rank operator]] combines its left operand's result cells by extending them to a common shape like [[Mix]] does. Numeric vectors of different lengths will be expanded with <code>0</code>, the prototype for a simple numeric array.
The [[Rank operator]] combines its left operand's result cells by extending them to a common shape like [[Mix]] does. Numeric vectors of different lengths will be expanded with <source lang=apl inline>0</code>, the prototype for a simple numeric array.
<source lang=apl>
<source lang=apl>
       (⍳⍤0) 2 3 4
       (⍳⍤0) 2 3 4
Line 22: Line 22:
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}


An array's prototype is based on its first element, so the array <code>a</code> below has a simple numeric prototype, as does any prefix of <code>a</code>. This property even applies to empty arrays: the expression <code>0 ↑ a</code> results in an empty array with the same prototype as <code>a</code>.  
An array's prototype is based on its first element, so the array <source lang=apl inline>a</code> below has a simple numeric prototype, as does any prefix of <source lang=apl inline>a</code>. This property even applies to empty arrays: the expression <source lang=apl inline>0 ↑ a</code> results in an empty array with the same prototype as <source lang=apl inline>a</code>.  
<source lang=apl>
<source lang=apl>
       ⊢a ← 5 'c' ¯2
       ⊢a ← 5 'c' ¯2

Navigation menu