Precedence

From APL Wiki
Revision as of 09:30, 6 October 2022 by Adám Brudzewsky (talk | contribs) (add nav box)
Jump to navigation Jump to search

In APL, there is no precedence hierarchy within a given name class - the role which a semantic object fulfills - for example, Arrays, Functions, and Operators have consistent binding strength and scope. So, the APL functions ÷, ×, *, + are evaluated in a precisely identical fashion. Unlike other languages, which choose to follow the traditional mathematical rules of precedence.

However, there is disparity in relative precedence between name classes. For example, an operator binds tighter to its operand, than a function does to its argument.

These differences can be enumerated in a table:

A F M D
A 4 2 3
F 1 3
M
D 3 3

Explanation

  • Categories:
    • Array
    • Function
    • Monadic Operator
    • Dyadic Operator

Array-array binds strongest, to produce an array (stranding).

Operator-Operand (Array or Function) binding follows, to produce a derived function.

Then functions are applied to their arguments. Note that functions have long right scope and short left scope, that is, everything to the right of a function is taken as a right argument, and as a left argument the first array to its left. So, functions are said to evaluate right to left.

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