Precedence

From APL Wiki
Revision as of 00:53, 6 October 2022 by Faun Locke (talk | contribs) (Created page with "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 <syntaxhighlight lang=apl inline>÷, ×, *, +</syntaxhighlight> are evaluated in a precisely identical fashion. Unlike other languages, which choose to follow the traditional mathematical rules of precedence. However, there is dispar...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.