Type: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com")
Line 5: Line 5:


== Support==
== Support==
Few dialects have Type 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''), which it inherited from [[NARS]]. [[Extended Dyalog APL]] uses monadic <source lang=apl inline>⍷</source> with the underscore indicating functionality of the corresponding non-underscored glyph from a non-default migration level.<ref>[[Partition]] is <source lang=apl inline>⊆</source> with migration level≤2 while the original glyph is <source lang=apl inline>⊂</source> as with migration level 3. Dyalog Language Reference Guide: [https://help.dyalog.com/latest/#Language/Symbols/Left%20Shoe.htm Left Shoe].</ref>
Few dialects have Type as a [[primitive function]]. [[APL2]] IUP had it,<ref>Graham, Alan. [https://dl.acm.org/doi/pdf/10.1145/22008.22033#page=4 Idioms and Problem Solving Techniques in APL2; Appendix - APL2 Idiom List: 9. Type]. [[APL86]].</ref> and thus [[Dyalog APL]] originally supported it too. However, by the time [[IBM]] released APL2, <source lang=apl inline>∊</source> (as in ''prototypical '''e'''lement'') 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>⊤</source> (resembling the Latin letter '''T''' for '''''T'''ype''), which it inherited from [[NARS]]. [[Extended Dyalog APL]] uses monadic <source lang=apl inline>⍷</source> with the underscore indicating functionality of the corresponding non-underscored glyph from a non-default migration level.<ref>[[Partition]] is <source lang=apl inline>⊆</source> with migration level≤2 while the original glyph is <source lang=apl inline>⊂</source> as with migration level 3. Dyalog Language Reference Guide: [https://help.dyalog.com/latest/#Language/Symbols/Left%20Shoe.htm Left Shoe].</ref>


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:
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:
Line 22: Line 22:
</source>
</source>
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}}
{{Works in|[[Dyalog APL]] with [[migration level]]<nowiki>=</nowiki>1}}
== External links ==
== External links ==
=== Documentation ===
=== Documentation ===

Revision as of 12:54, 27 July 2022

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, (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 (resembling the Latin letter T for Type), which it inherited from NARS. Extended Dyalog APL uses monadic 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:

      ↑ 0 ⍴ ⊂ 1 2 'ab'
┌─┬─┬──┐
│0│0│  │
└─┴─┴──┘
Works in: Dyalog APL with migration level≥2, APL2, APLX
      ⊃ 0 ⍴ ⊂ 1 2 'ab'
┌─┬─┬──┐
│0│0│  │
└─┴─┴──┘
Works in: Dyalog APL with migration level=1

External links

Documentation

References

  1. Graham, Alan. Idioms and Problem Solving Techniques in APL2; Appendix - APL2 Idiom List: 9. Type. APL86.
  2. Partition is with migration level≤2 while the original glyph is as with migration level 3. Dyalog Language Reference Guide: Left Shoe.
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector