Type
∊ ⊤ ⍷
|
Type (∊
, ⊤
, ⍷
) is a monadic scalar function which in the nested array model gives information about the type and structure of its argument array's elements. In normal cases, the result is identical to the argument, with all numbers replaced by zeros and all characters replaced by spaces, and the substitution is done recursively.
Support
Few dialects have Type as a primitive function. APL2 IUP had it,[1] and thus Dyalog APL originally supported it too. However, by the time IBM released APL2, <source lang=apl inline>∊</syntaxhighlight> (as in prototypical element) was repurposed for Enlist. Thus, Dyalog left the Type meaning in place only when migration level is 0, while setting it to 1 or higher follows IBM's replacement meaning. NARS2000 uses monadic <source lang=apl inline>⊤</syntaxhighlight> (resembling the Latin letter T for Type), which it inherited from NARS. Extended Dyalog APL uses monadic <source lang=apl inline>⍷</syntaxhighlight> with the underscore indicating functionality of the corresponding non-underscored glyph from a non-default migration level.[2]
However, in all dialects that support nested arrays, the type can be determined by enclosing/boxing the array in an empty array, and then coercing out a fill value. Since the array prototype is used as fill element, the resulting array will be the type of the original array: <source lang=apl>
↑ 0 ⍴ ⊂ 1 2 'ab'
┌─┬─┬──┐ │0│0│ │ └─┴─┴──┘ </syntaxhighlight>
<source lang=apl>
⊃ 0 ⍴ ⊂ 1 2 'ab'
┌─┬─┬──┐ │0│0│ │ └─┴─┴──┘ </syntaxhighlight>
External links
Documentation
References
- ↑ Graham, Alan. Idioms and Problem Solving Techniques in APL2; Appendix - APL2 Idiom List: 9. Type. APL86.
- ↑ Partition is <source lang=apl inline>⊆</syntaxhighlight> with migration level≤2 while the original glyph is <source lang=apl inline>⊂</syntaxhighlight> as with migration level 3. Dyalog Language Reference Guide: Left Shoe.