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.
An operator's valence indicates the number of operands it takes:
- A monadic operator takes one operand to its left (except Outer Product, which has a special syntax).
- A dyadic operator takes a left and a right operand.
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 |
|General||Comparison with traditional mathematics ∙ Precedence ∙ Tacit programming|
|Array||Numeric literal ∙ String ∙ Strand notation ∙ Object literal ∙ Array notation|
|Function||Argument ∙ Function valence ∙ Derived function ∙ Derived operator ∙ Niladic function ∙ Monadic function ∙ Dyadic function ∙ Ambivalent function ∙ Tradfn ∙ Dfn ∙ Function train|
|Operator||Operand ∙ Operator valence ∙ Tradop ∙ Dop ∙ Derived operator|
|Assignment||Multiple ∙ Indexed ∙ Selective ∙ Modified|
|Other||Function axis ∙ Branching ∙ System command ∙ User command ∙ Keyword ∙ Dot notation|