APL syntax and symbols

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.

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.

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 +.

The left scope of each is terminated by the reduce operator, denoted by the forward slash.

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

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.

For example, given the ⌽ (reversal) function and a two-dimensional array, the function by default operates along the last axis but this can be changed using an axis indicator: 4 rows by 3 cols matrix created, using rho ⍴ and iota ⍳.

A is ⍉ transposed to a 3 row by 4 col matrix such that rows-cols become exchanged, as symbol ⍉ visually portrays.

These types of data transformations are useful in time series analysis and spatial coordinates, just two examples, more exist.

As a particular case, if the dyadic catenate "," function is followed by an axis indicator (or axis modifier to a symbol/function), it can be used to laminate (interpose) two arrays depending on whether the axis indicator is less than or greater than the index origin[8] (index origin = 1 in illustration below): At left, variable 'B' is first assigned a vector of 4 consecutive integers (e.g., ⍳4).Var C is then assigned 4 more consecutive integers (such as 4+⍳4).

In the particular case at left, if the dyadic catenate "," function is followed by an axis indicator ([0.5] which is less than 1), it can be used to laminate (interpose) two arrays (vectors in this case) depending on whether the axis indicator is less than or greater than the index origin(1).

A user may define custom functions which, like variables, are identified by name rather than by a non-textual symbol.

There are exceptions to this, for example a function to convert pre-decimal UK currency to dollars would expect to take a parameter with precisely three elements representing pounds, shillings and pence.

[11] Inside a program or a custom function, control may be conditionally transferred to a statement identified by a line number or explicit label; if the target is 0 (zero) this terminates the program or returns to a function's caller.

Hence function SEGMENTAREA may be modified to abort (just below), returning zero if the parameters (DEGREES and RADIUS below) are of different sign: The above function SEGMENTAREA works as expected if the parameters are scalars or single-element arrays, but not if they are multiple-element arrays since the condition ends up being based on a single element of the SIGN array - on the other hand, the user function could be modified to correctly handle vectorized arguments.

The below importantly correctly handles vectorized arguments: Avoiding explicit transfers of control also called branching, if not reviewed or carefully controlled - can promote use of excessively complex one liners, veritably "misunderstood and complex idioms" and a "write-only" style, which has done little to endear APL to influential commentators such as Edsger Dijkstra.

Most APL implementations support a number of system variables and functions, usually preceded by the ⎕ (quad) and/or ")" (hook=close parenthesis) character.

Particularly important and widely implemented is the ⎕IO (Index Origin) variable, since while the original IBM APL based its arrays on 1 some newer variants base them on zero: X set = to vector of 12 consecutive integers.

There are also system functions available to users for saving the current workspace e.g., )SAVE and terminating the APL environment, e.g., )OFF - sometimes called hook commands or functions due to the use of a leading right parenthesis or hook.

The Unicode Basic Multilingual Plane includes the APL symbols in the Miscellaneous Technical block,[17] which are thus usually rendered accurately from the larger Unicode fonts installed with most modern operating systems.

Also note the keyboard had some 55 unique (68 listed per tables above, including comparative symbols but several symbols appear in both monadic and dyadic tables) APL symbol keys (55 APL functions (operators) are listed in IBM's 5110 APL Reference Manual), thus with the use of alt, shift and ctrl keys - it would theoretically have allowed a maximum of some 59 (keys) *4 (with 2-key pressing) *3 (with tri-key pressing, e.g., ctrl-alt-del) or some 472 different maximum key combinations, approaching the 512 EBCDIC character max (256 chars times 2 codes for each keys-combination).

In practice, early versions were only using something roughly equivalent to 55 APL special symbols (excluding letters, numbers, punctuation, etc.

Thus, early APL was then only using about 11% (55/472) of a symbolic language's at-that-time utilization potential, based on keyboard # keys limits, again excluding numbers, letters, punctuation, etc.

In another sense keyboard symbols utilization was closer to 100%, highly efficient, since EBCDIC only allowed 256 distinct chars, and ASCII only 128.

Visual representation of the nested array
APL2 Keyboard
APL2 Keyboard