Identity operator: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Create Identity operator)
 
m (add category and navbox)
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
Null and Ident are [[monadic operator|monadic operators]] that return the only operand, Lev and Dex are [[dyadic operator|dyadic operators]] that respectively return the left and right operand.
Null and Ident are [[monadic operator|monadic operators]] that return the only operand, Lev and Dex are [[dyadic operator|dyadic operators]] that respectively return the left and right operand.


## Examples
== Examples ==


<syntaxhighlight lang="apl">
<syntaxhighlight lang="apl">
Line 45: Line 45:
* TinyAPL: [https://tinyapl.rubenverg.com/docs/primitive/ident Ident], [https://tinyapl.rubenverg.com/docs/primitive/lev Lev], [https://tinyapl.rubenverg.com/docs/primitive/dex Dex]
* TinyAPL: [https://tinyapl.rubenverg.com/docs/primitive/ident Ident], [https://tinyapl.rubenverg.com/docs/primitive/lev Lev], [https://tinyapl.rubenverg.com/docs/primitive/dex Dex]
* J: [https://code.jsoftware.com/wiki/Vocabulary/squarertco Ident], [https://code.jsoftware.com/wiki/Vocabulary/squarelfdot Lev], [https://code.jsoftware.com/wiki/Vocabulary/squarertdot Dex]
* J: [https://code.jsoftware.com/wiki/Vocabulary/squarertco Ident], [https://code.jsoftware.com/wiki/Vocabulary/squarelfdot Lev], [https://code.jsoftware.com/wiki/Vocabulary/squarertdot Dex]
{{APL built-ins}}[[Category:Primitive operators]]

Latest revision as of 06:50, 1 November 2024

An identity operator is an operator which returns (one of) the operand(s). These are Null () in NARS2000; Ident (), Lev () and Dex () in TinyAPL; Ident (]:), Lev ([.) and Dex (].) in J.

Null and Ident are monadic operators that return the only operand, Lev and Dex are dyadic operators that respectively return the left and right operand.

Examples

      9 -⊙ 5
4
Works in: NARS2000
      3 -⫤ 1
2
      2 +⫣× 5
7
      2 +⊩× 5
10
Works in: TinyAPL

Description

In the simplest definition, the operators just return the functions as described above. Where implementations diverge is in the handling of array operands. NARS2000 disallows this in its Null operator. TinyAPL chooses to return a constant function, as if arr⍨⫤ and similar were written, J makes the three operators behave specially and allows them to return arrays:

   2]:+1
3
Works in: J

Purpose

The reason why identity operators exist in NARS2000 and J and TinyAPL are different. In NARS2000, / and other glyphs are hybrids, which means that they can both mean functions or operators. Null solves this by casting the operand to a function. J and TinyAPL introduced the three identity operators as a result of the introduction of modifier trains, which are a generalization of trains to operator tines. When one wants to not process one of the tines and return the operand directly, an identity operator is needed. In other words, identity functions are to arguments as identity operators are to operands.

External links

Documentation


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
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 axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector