Overview of the APL System
APLX incorporates the International Standards Organisation (ISO) draft specification of APL. It conforms to that specification in all important respects. APLX also conforms closely to the specification for APL2 as detailed in the IBM Manual 'APL2 Programming Language Reference' (SH20-9227-3).
Whilst retaining compatibility with APL2, APLX Version 4 adds object-oriented language extensions, as well as a large number of other facilities, to the language.
The APLX Interpreter
Statements in a computer language have to be converted into the code used by the computer before they can be executed. APL is an interpreted language which means this process is done line-by-line at the time of execution. The program which does the conversion is the APL interpreter.
This is an area in the computer's random access memory where the programs and data on which you're working reside. Other programs and data can be brought in from disc, but only items in the workspace are available for calculation or processing.
You can type data in at the keyboard, or store it on a disc and load it into the workspace when required. It can consist of numbers or characters or both. (A character is any letter, numeral or symbol on the keyboard.)
Data is held in structures called arrays. An array can be:
Each data item in an array can be either:
Arrays containing both characters and numbers are called mixed and arrays which have elements which are themselves arrays are called nested arrays.
There is also some special cases:
You can use numbers and letters directly in APL, or you can give names to them and use the names instead. An array to which you give a name is a variable.
The earlier section avoided the use of the formal names for APL data and variables, but these names will be used from now on.
There are three modes in APL. In calculator mode each APL statement is executed as you enter it. In definition mode, the APL statements you enter are not executed immediately, but are stored as a user-defined function or operator, the equivalent of a program. When you run a user-defined function or operator, you're in function execution mode.
Built-in functions and operators
These are the operations that are built into the APL language. There are about fifty functions, each invoked by a single symbol (
Functions are said to operate on arguments. Here the add function has a left and a right argument:
129 + 34
⍴ 18 67 2
Most of the functions can perform two different (though usually related) operations depending on whether they're used with one or two arguments. This effectively doubles the repertoire of operations available to you.
Five operators are also built-in to the language. You can use an operator with a function to modify or extend the way the function works. An operator has one or more operands (usually functions) which are applied to one or more arguments. The combination of an operator and its operand or operands is called a derived function. Derived functions may in turn be used as operands to operators.
System functions and variables
These are part of the APL system but strictly speaking aren't part of the APL language. They extend the facilities provided by the original APL language and their implementation tends to be tailored to the computer on which the APL system is running.
For example, you can read and write data from files using
You can use system variables and functions in your programs. Their names always start with
Again, these are part of the APL system but aren't part of the APL language itself. Most of them are concerned with managing the workspace. For example, you use system commands to clear the workspace or to save a copy of it on a disc -
System commands are normally typed in at the keyboard and executed directly, though it's possible to include them in programs if you want to. System commands are always preceded by a right facing parenthesis,
User-defined functions and operators
These are functions or operators you write yourself while in definition mode. They consist of APL statements and have a name. You can use this name in calculator mode, or you can include the name in another function or operator to cause execution while that function or operator is running.
You can write a function or operator to supplement the repertoire supplied by the system. For example, if you had to use the statistical measure standard deviation frequently, you might write a standard deviation function, and use it subsequently exactly like a built-in function.
You can also write functions which are the equivalent of programs in other languages.
A function editor enables you to create functions or operators and subsequently make insertions, deletions and amendments. All versions of APLX will have a simple line editor and usually will also have a full-screen editor (see implementation notes for details).
Most programming languages use external files of data if there's too much data to embed in the program itself.
When you use APL, any data you want to process will usually be in the workspace in memory. Occasionally you may have to bring in more data from a workspace held on a disc. But the workspace is so extremely convenient for holding both simple and more complicated data structures, that only with bigger projects will you find it necessary to set up files in the traditional sense.
In multi-user environments, you may wish to use files to share data between users.
When you do need to work with files, APLX has the facilities for handling them.
An error in a statement will usually cause an error message to be displayed. There are various messages which identify the most common errors. If an error occurs during execution of a user-defined function, information which will help locate the error is automatically displayed. There are facilities for error trapping, together with various other testing and diagnostic aids.
APL doesn't have many rules about the way expressions are written. You can use almost any logical combination of variables and functions together on the same line:
RESULT ← ⌈l000,3×4÷22+QTY
There are some common sense rules about spacing. These, and the few other syntax rules that exist in APLX, are given in the APLX Language Manual.
Copyright © 1996-2008 MicroAPL Ltd