Identity operator: Difference between revisions
m (oops) |
m (add category and navbox) |
||
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
3 -⫤ 1 2 2 +⫣× 5 7 2 +⊩× 5 10
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
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