APLX Help : Help on APL language : APL Fundamentals : Binding strengths


Binding strengths 

In simple terms, APL evaluates expressions righttoleft, that is to say the result of the rightmost function is evaluated, and becomes the right argument of the next function. There are no 'precedence rules' to remember; all primitive and userdefined functions have the same precedence. For example: 5⍴3.2×12÷4 9.6 9.6 9.6 9.6 9.6 In this example, the division The right to left function execution rule needs to be modified to cope with more complex expressions, for example nested vectors or certain expressions containing operators. The 'binding strength' defines how certain symbols 'bind' for evaluation. The order of binding strengths is shown below, in descending order. (Note that binding strengths can be altered by the
Parentheses can override the binding strength hierarchy. Some examples include: A←'DEF' (Set up variables A B) B←'XYZ' A B DEF XYZ A B[2] ([] has higher binding than vector so the DEF Y result includes the second element of B) (A B)[2] (Parentheses force selection of B) XYZ A B←3 (← has stronger binding than vector) DEF 3 (A B)←3 (Parentheses alter binding) A 3 B 3 1 2 3 + 4 5 6 (Vector has stronger binding than function) 5 7 9 1 2 (3+4) 5 6 (Parentheses alter binding) 1 2 7 5 6 1 0 1/'ABC' (Vector has stronger binding than left AC operand, so left operand is 1 0 1) +/[2]2 2⍴⍳4 (Axis brackets have stronger binding than 3 7 operator to operands, so /[2] operator is formed Finally, the relative binding strengths of left and right operands can be used to predict the result of expressions with multiple operators. 

APLX Help : Help on APL language : APL Fundamentals : Binding strengths

Copyright © 19962010 MicroAPL Ltd