Prototype: Difference between revisions

Jump to navigation Jump to search
126 bytes added ,  22:03, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - " ⊢( *[^∘])" to " ⎕←$1")
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 3: Line 3:
== 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 <source lang=apl inline>' '</source> 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>' '</syntaxhighlight> is the prototype of a character array:
<source lang=apl>
<source lang=apl>
       ¯12 ↑ 'whitespace'
       ¯12 ↑ 'whitespace'
Line 9: Line 9:
       (5 1 5/1 ¯2 1) \ 'whitespace'
       (5 1 5/1 ¯2 1) \ 'whitespace'
white  space
white  space
</source>
</syntaxhighlight>


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</source>, 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</syntaxhighlight>, the prototype for a simple numeric array.
<source lang=apl>
<source lang=apl>
       (⍳⍤0) 2 3 4
       (⍳⍤0) 2 3 4
Line 17: Line 17:
1 2 3 0
1 2 3 0
1 2 3 4
1 2 3 4
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}


An array's prototype is based on its first element, so the array <source lang=apl inline>a</source> below has a simple numeric prototype, as does any prefix of <source lang=apl inline>a</source>. This property even applies to empty arrays: the expression <source lang=apl inline>0 ↑ a</source> results in an empty array with the same prototype as <source lang=apl inline>a</source>.  
An array's prototype is based on its first element, so the array <source lang=apl inline>a</syntaxhighlight> below has a simple numeric prototype, as does any prefix of <source lang=apl inline>a</syntaxhighlight>. This property even applies to empty arrays: the expression <source lang=apl inline>0 ↑ a</syntaxhighlight> results in an empty array with the same prototype as <source lang=apl inline>a</syntaxhighlight>.  
<source lang=apl>
<source lang=apl>
       ⎕←a ← 5 'c' ¯2
       ⎕←a ← 5 'c' ¯2
Line 30: Line 30:
       4 ↑ 0 ↑ a
       4 ↑ 0 ↑ a
0 0 0 0
0 0 0 0
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}


Line 52: Line 52:
│  │0 0 0│
│  │0 0 0│
└──┴─────┘
└──┴─────┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}


Line 62: Line 62:
│0│0│  │
│0│0│  │
└─┴─┴──┘
└─┴─┴──┘
</source>
</syntaxhighlight>
{{Works in|[[NARS2000]]}}
{{Works in|[[NARS2000]]}}
<source lang=apl>
<source lang=apl>
Line 69: Line 69:
│0│0│  │
│0│0│  │
└─┴─┴──┘
└─┴─┴──┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>0}}
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>0}}
However, an array's prototype can always be determined by reshaping the array to become empty, and then coercing out a fill element:
However, an array's prototype can always be determined by reshaping the array to become empty, and then coercing out a fill element:
Line 77: Line 77:
│0│0│  │
│0│0│  │
└─┴─┴──┘
└─┴─┴──┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>≥</nowiki>2, [[APL2]], [[APLX]]}}
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>≥</nowiki>2, [[APL2]], [[APLX]]}}
[https://tryapl.org/?a=%u2283%200%20%u2374%20%281%202%20%27ab%27%29%203%204&run Try it now!]
[https://tryapl.org/?a=%u2283%200%20%u2374%20%281%202%20%27ab%27%29%203%204&run Try it now!]
Line 85: Line 85:
│0│0│  │
│0│0│  │
└─┴─┴──┘
└─┴─┴──┘
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}}
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}}


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]].
{{APL features}}[[Category:Array relationships]][[Category:Array characteristics]]
{{APL features}}[[Category:Array relationships]][[Category:Array characteristics]]

Navigation menu