Prototype: Difference between revisions

Jump to navigation Jump to search
20 bytes added ,  14:58, 17 October 2019
no edit summary
Miraheze>Marshall
(Created page with "In the nested array model, an array's prototype is an array which gives information about the type and structure of its elements. It is derived from the first...")
 
Miraheze>Adám Brudzewsky
No edit summary
Line 6: Line 6:


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 <code>' '</code> is the prototype of a character array:
<pre class=apl>
<source lang=apl>
       ¯12 ↑ 'whitespace'
       ¯12 ↑ 'whitespace'
   whitespace
   whitespace
       (5 1 5/1 ¯2 1) \ 'whitespace'
       (5 1 5/1 ¯2 1) \ 'whitespace'
white  space
white  space
</pre>
</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 <code>0</code>, the prototype for a simple numeric array.
<pre class=apl>
<source lang=apl>
       (⍳⍤0) 2 3 4
       (⍳⍤0) 2 3 4
1 2 0 0
1 2 0 0
1 2 3 0
1 2 3 0
1 2 3 4
1 2 3 4
</pre>
</source>
{{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 <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>.  
<pre class=apl>
<source lang=apl>
       ⊢a ← 5 'c' ¯2
       ⊢a ← 5 'c' ¯2
5 c ¯2
5 c ¯2
Line 32: Line 32:
       4 ↑ 0 ↑ a
       4 ↑ 0 ↑ a
0 0 0 0
0 0 0 0
</pre>
</source>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}


The prototype of an array may be nested. Here, we inspect the prototype of an array containing both character and numeric data. In the prototype, all characters are converted to spaces and all numbers to zeros. Thus the prototype retains type and structure information but not specific values.
The prototype of an array may be nested. Here, we inspect the prototype of an array containing both character and numeric data. In the prototype, all characters are converted to spaces and all numbers to zeros. Thus the prototype retains type and structure information but not specific values.
<pre class=apl>
<source lang=apl>
       ⊢x ← ⊂'de'(3 4 5)  ⍝ A complicated scalar array
       ⊢x ← ⊂'de'(3 4 5)  ⍝ A complicated scalar array
┌──────────┐
┌──────────┐
Line 54: Line 54:
│  │0 0 0│
│  │0 0 0│
└──┴─────┘
└──┴─────┘
</pre>
</source>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}

Navigation menu