Operator: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "In APL syntax, an '''operator''' applies to function or array operands to yield a derived function result. Operators bind with higher precedence than f...")
 
m (Operators category)
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
* A [[dyadic operator]] takes a left and a right operand.
* A [[dyadic operator]] takes a left and a right operand.
Unlike with [[monadic]] and [[dyadic function]]s, an operator's valence is an intrinsic property and must be known in order to parse an APL expression containing it. Also unlike [[function]]s, there is no such thing as a "niladic operator" taking no operands, because this would be indistinguishable from a [[niladic function]].
Unlike with [[monadic]] and [[dyadic function]]s, an operator's valence is an intrinsic property and must be known in order to parse an APL expression containing it. Also unlike [[function]]s, there is no such thing as a "niladic operator" taking no operands, because this would be indistinguishable from a [[niladic function]].
In [[Iverson notation]] and early APL interpreters, operators were not considered together as a class. Instead, each was thought of as its own piece of syntax. Eventually operators came to be thought of in the modern sense as higher-order functions. As a result, in most modern APLs operators can be applied to any function rather than a limited set ([[A+]] is a relatively recent exception), the programmer can [[defined operator|define]] their own operators, and existing operators (such as [[primitive operator]]s and [[dop]]s) can be [[assignment|assigned]] names. However, some syntactic oddities remain as a result of treating operators as a special syntax: the [[Outer Product]] is written with two symbols when one would work just as well, and some operators share glyphs with operations that seem to be [[function]]s, for example [[Reduce]] and [[Replicate]]. The latter condition has led to the introduction of [[function-operator overloading]] in some APLs.
Newer languages like [[J]] and [[K]] which do not maintain [[backwards compatibility]] with APL usually make the operator syntax more regular. In [[J]], operators (termed "adverbs" for [[monadic operator|monadic]] and "conjunctions" for [[dyadic operator]]s) are considered simply as higher-order functions and there is no concept of a [[derived function]]. An operator can return any array or function, or even another operator.
{{APL syntax}}[[Category:Operators| ]]

Latest revision as of 15:15, 30 April 2020

In APL syntax, an operator applies to function or array operands to yield a derived function result. Operators bind with higher precedence than functions and are grouped from left to right, the opposite of APL's right to left evaluation order for functions. In most cases operators cannot themselves be modified, but reductions and scans do take a specified axis, and in some APLs hyperators can take operator hyperands.

Operators may be primitive operators, system operators, or defined operators. In some APLs it is also possible to produce a derived operator by passing only one operand to a dyadic operator.

An operator's valence indicates the number of operands it takes:

Unlike with monadic and dyadic functions, an operator's valence is an intrinsic property and must be known in order to parse an APL expression containing it. Also unlike functions, there is no such thing as a "niladic operator" taking no operands, because this would be indistinguishable from a niladic function.

In Iverson notation and early APL interpreters, operators were not considered together as a class. Instead, each was thought of as its own piece of syntax. Eventually operators came to be thought of in the modern sense as higher-order functions. As a result, in most modern APLs operators can be applied to any function rather than a limited set (A+ is a relatively recent exception), the programmer can define their own operators, and existing operators (such as primitive operators and dops) can be assigned names. However, some syntactic oddities remain as a result of treating operators as a special syntax: the Outer Product is written with two symbols when one would work just as well, and some operators share glyphs with operations that seem to be functions, for example Reduce and Replicate. The latter condition has led to the introduction of function-operator overloading in some APLs.

Newer languages like J and K which do not maintain backwards compatibility with APL usually make the operator syntax more regular. In J, operators (termed "adverbs" for monadic and "conjunctions" for dyadic operators) are considered simply as higher-order functions and there is no concept of a derived function. An operator can return any array or function, or even another operator.


APL syntax [edit]
General Comparison with traditional mathematicsPrecedenceTacit programming (Train, Hook, Split composition)
Array Numeric literalStringStrand notationObject literalArray notation (design considerations)
Function ArgumentFunction valenceDerived functionDerived operatorNiladic functionMonadic functionDyadic functionAmbivalent functionDefined function (traditional)DfnFunction train
Operator OperandOperator valenceTradopDopDerived operator
Assignment MultipleIndexedSelectiveModified
Other Function axisBracket indexingBranchStatement separatorQuad nameSystem commandUser commandKeywordDot notationFunction-operator overloadingControl structureComment