*** Welcome to piglix ***

APL syntax and symbols


The APL programming language 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.

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.

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, ref. IBM's 5100 APL Reference Manual, first edition, circa 1975. 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:

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

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.


...
Wikipedia

...