The programming language APL is distinctive in being symbolic rather than lexical: its primitives are denoted by symbols, not words. These symbols were originally devised as a mathematical notation to describe algorithms. APL programmers often assign informal names when discussing functions and operators (for example, "product" for ×/) but the core functions and operators provided by the language are denoted by non-textual symbols.

Monadic and dyadic functions Most symbols denote functions or operators. A monadic function takes as its argument the result of evaluating everything to its right. (Moderated in the usual way by parentheses.) A dyadic function has another argument, the first item of data on its left. Many symbols denote both monadic and dyadic functions, interpreted according to use. For example, ⌊3.2 gives 3, the largest integer not above the argument, and 3⌊2 gives 2, the lower of the two arguments.

Functions and operators APL uses the term operator in Heaviside’s sense as a moderator of a function as opposed to some other programming language's use of the same term as something that operates on data, ref. relational operator and operators generally. Other programming languages also sometimes use this term interchangeably with function, however both terms are used in APL more precisely. Early definitions of APL symbols were very specific about how symbols were categorized. For example, the operator reduce is denoted by a forward slash and reduces an array along one axis by interposing its function operand. An example of reduce:

×/2 3 4 24 << Equivalent results in APL >> << Reduce operator / used at left 2×3×4 24 In the above case, the reduce or slash operator moderates the multiply function. The expression ×/2 3 4 evaluates to a scalar (1 element only) result through reducing an array by multiplication. The above case is simplified, imagine multiplying (adding, subtracting or dividing) more than just a few numbers together. (From a vector, ×/ returns the product of all its elements.)

1 0 1\45 67 45 0 67 << Opposite results in APL >> << Expand dyadic function \ used at left Replicate dyadic function / used at right >> 1 0 1/45 0 67 45 67 The above dyadic functions examples [left and right examples] (using the same / symbol, right example) demonstrate how Boolean values (0s and 1s) can be used as left arguments for the \ expand and / replicate functions to produce exactly opposite results. On the left side, the 2-element vector {45 67} is expanded where Boolean 0s occur to result in a 3-element vector {45 0 67} — note how APL inserted a 0 into the vector. Conversely, the exact opposite occurs on the right side — where a 3-element vector becomes just 2-elements; Boolean 0s delete items using the dyadic / slash function. APL symbols also operate on lists (vector) of items using data types other than just numeric, for example a 2-element vector of character strings {"Apples" "Oranges"} could be substituted for numeric vector {45 67} above.

Syntax rules In APL the precedence hierarchy for functions or operators is strictly positional: expressions are evaluated right-to-left. APL does not follow the usual operator precedence of other programming languages; for example, × does not bind its operands any more "tightly" than +. Instead of operator precedence, APL defines a notion of scope.

The scope of a function determines its arguments. Functions have long right scope: that is, they take as right arguments everything to their right. A dyadic function has short left scope: it takes as its left arguments the first piece of data to its left. For example, (leftmost column below is actual program code from an APL user session, indented = actual user input, not-indented = result returned by APL interpreter):

1 ÷ 2 ⌊ 3 × 4 - 5 ¯0.3333333333 1 ÷ 2 ⌊ 3 × ¯1 ¯0.3333333333 1 ÷ 2 ⌊ ¯3 ¯0.3333333333 1 ÷ ¯3 ¯0.3333333333

<< First note there are no parentheses and APL is going to execute from right-to-left. Step 1{of topmost APL code entered at left}) 4-5 = -1.

Step 2) 3 times -1 = -3. Step 3) Take the floor or lower of 2 and -3 = -3. Step 4) Divide 1 by -3 = -0.3333333333 = final result.

An operator may have function or data operands and evaluate to a dyadic or monadic function. Operators have long left scope. An operator takes as its left operand the longest function to its left. For example:

∘.=/⍳¨3 3 1 0 0 0 1 0 0 0 1

APL atomic or piecemeal sub-analysis (full explanation): Beginning rightmost: ⍳¨3 3 produces a 2-element nested APL vector { {1 2 3} {1 2 3} } where each element is itself a vector {1 2 3}. Iota ⍳3 by itself would produce {1 2 3}.

The diaeresis ¨ or mini double-dot means repeat or over each or perform each separately so iota repeats (in human i.e., reversed terms, the APL interpreter reads 3 3 over each use iota), concisely: iota for each 3.

The left operand for the over-each operator ¨ is the index ⍳ function. The derived function ⍳¨ is used monadically and takes as its right operand the vector 3 3. The left scope of each is terminated by the reduce operator, denoted by the forward slash. Its left operand is the function expression to its left: the outer product of the equals function. The result of ∘.=/ is a monadic function. With a function's usual long right scope, it takes as its right argument the result of ⍳¨3 3. Thus

(⍳3)(⍳3) 1 2 3 1 2 3 (⍳3)∘.=⍳3 1 0 0 0 1 0 0 0 1

1 2 3 1 2 3 ∘.=/⍳¨3 3 1 0 0 0 1 0 0 0 1

Equivalent results in APL: (⍳3)(⍳3) and << Rightmost expression is .

The matrix of 1s and 0s similarly produced by ∘.=/⍳¨3 3 and (⍳3)∘.=⍳3 is called an identity matrix.

Identity matrices are useful in solving matrix determinants, groups of linear equations and multiple regression.

im ← ∘.=⍨∘⍳ im 3 1 0 0 0 1 0 0 0 1

Some APL interpreters support the compose operator ∘ and the commute operator ⍨. The former ∘ glues functions together so that foo∘bar, for example, could be a hypothetical function that applies defined function foo to the result of defined function bar; foo and bar can represent any existing function. In cases where a dyadic function is moderated by commute and then used monadically, its right argument is taken as its left argument as well. Thus, a derived or composed function (named im at left) is used in the APL user session to return a 9-element identity matrix using its right argument, parameter or operand = 3.

Letters←"ABCDE" Letters ABCDE ⍴Letters 5 FindIt←"CABS" FindIt CABS ⍴FindIt 4

Letters ⍳ FindIt 3 1 2 6

Example using APL to index ⍳ or find (or not find) elements in a character vector:

First, variable Letters is assigned a vector of 5-elements, in this case - letters of the alphabet.

The shape ⍴ or character vector-length of Letters is 5.

Variable FindIt is assigned what to search for in Letters and its length is 4 characters.

1 2 3 4 5 << vector positions or index #'s in Letters ABCDE

At left, dyadic function iota searches through its left argument(Letters) for the search string (iota's right argument, FindIt).

Iota finds letter "C" at position 3 in Letters, it finds "A" at position 1, and "B" at position 2. Iota does not find letter "S"

anywhere in variable Letters so it returns the number 6 which is 1 greater than the length of Letters. Iota found letters

"CAB" (3 1 2). Iota correctly did not find "S" (6).

Monadic functions Name(s) Notation Meaning Unicode code point Roll One integer selected randomly from the first B integers Ceiling Least integer greater than or equal to B Floor Greatest integer less than or equal to B Shape, Rho Number of components in each dimension of B Not, Tilde Logical: 1 is 0, 0 is 1 Absolute value Magnitude of B Index generator, Iota Vector of the first B integers Exponential e to the B power Negation Changes sign of B Conjugate The complex conjugate of B (real numbers are returned unchanged) Signum ¯1 if B<0; 0 if B=0; 1 if B>0 Reciprocal 1 divided by B Ravel, Catenate, Laminate Reshapes B into a vector Matrix inverse, Monadic Quad Divide Inverse of matrix B Pi times Multiply by π Logarithm Natural logarithm of B Reversal Reverse elements of B along last axis Reversal Reverse elements of B along first axis Grade up Indices of B which will arrange B in ascending order Grade down Indices of B which will arrange B in descending order Execute Execute an APL expression Monadic format A character representation of B Monadic transpose Reverse the axes of B Factorial Product of integers 1 to B Depth Nesting depth: 1 for un-nested array Table Makes B into a table, a 2-dimensional array.

Dyadic functions Name(s) Notation Meaning Unicodecode point Add Sum of A and B Subtract A minus B Multiply A multiplied by B Divide A divided by B Exponentiation A raised to the B power Circle Trigonometric functions of B selected by A A=1: sin(B) A=2: cos(B) A=3: tan(B)

A=5: sinh(B) A=6: cosh(B) A=7: tanh(B) Negatives produce the inverse of the respective functions Deal A distinct integers selected randomly from the first B integers (without replacement) Membership, Epsilon 1 for elements of A present in B; 0 where not. Find, Epsilon Underbar 1 for starting point of multi-item array A present in B; 0 where not. Maximum, Ceiling The greater value of A or B Minimum, Floor The smaller value of A or B Reshape, Dyadic Rho Array of shape A with data B Take Select the first (or last) A elements of B according to ×A Drop Remove the first (or last) A elements of B according to ×A Decode Value of a polynomial whose coefficients are B at A Encode Base-A representation of the value of B Residue B modulo A; A divides B Catenation Elements of B appended to the elements of A Expansion, Dyadic Backslash Insert zeros (or blanks) in B corresponding to zeros in A Compression, Dyadic Slash Select elements in B corresponding to ones in A Index of, Dyadic Iota The location (index) of B in A; if not found Solution to system of linear equations, multiple regression Ax = B Rotation The elements of B are rotated A positions Rotation The elements of B are rotated A positions along the first axis Logarithm Logarithm of B to base A Dyadic format Format B into a character matrix according to A General transpose The axes of B are ordered by A Combinations Number of combinations of B taken A at a time Diaeresis, Dieresis, Double-Dot Over each, or perform each separately; B = on these; A = operation to perform or using (e.g., iota) Less than Comparison: 1 if true, 0 if false Less than or equal Comparison: 1 if true, 0 if false Equal Comparison: 1 if true, 0 if false Greater than or equal Comparison: 1 if true, 0 if false Greater than Comparison: 1 if true, 0 if false Not equal Comparison: 1 if true, 0 if false Or Boolean Logic: 0 (False) if both A and B = 0, 1 otherwise. Alt: 1 (True) if A or B = 1 (True) And Boolean Logic: 1 (True) if both A and B = 1, 0 (False) otherwise Nor Boolean Logic: 1 if both A and B are 0, otherwise 0. Alt: ~∨ = not Or Nand Boolean Logic: 0 if both A and B are 1, otherwise 1. Alt: ~∧ = not And Left A Right B Match 1 if A matches B exactly with respect to value, shape, and nesting; otherwise 0. Laminate Concatenate along first axis

Operators and axis indicator Name(s) Symbol Example Meaning (of example) Unicode code point sequence Reduce (last axis), Slash / Sum across B Reduce (first axis) ⌿ Sum down B Scan (last axis), Backslash \ Running sum across B Scan (first axis) ⍀ Running sum down B Inner product . Matrix product of A and B Outer product ∘. Outer product of A and B , Notes: The reduce and scan operators expect a dyadic function on their left, forming a monadic composite function applied to the vector on its right.