Overview of the APL System (7 of 14)

APL specification

There are two APL standards to which most APL versions conform in whole or in part:

APL vendors also add their own proprietory extensions to APL, for example object-oriented language support in Dyalog.

The APL Interpreter

Statements in a computer language have to be converted into the code used by the computer before they can be executed. Many APL implementations use a proprietary 'interpreter' to perform this conversion from human-entered code to computer code. Program code is interpreted line-by-line at the time of execution. The program which does the conversion is an APL interpreter.

The workspace

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 other sources such as a computer disc, but generally only items in the workspace are available for calculation or processing.

Data

You can type data in at the keyboard, or store it on a disc or external database 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.

Note:

The earlier section avoided the use of the formal names for APL data and variables, but these names will be used from now on.

Modes

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

Here the function has one argument, a vector of three numbers:

      ⍴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 varies from one APL vendor to another; they also tend to be tailored to the computer on which the APL system is running.

For example, in many APLs you can read and write data from files using ⎕NREAD and ⎕NWRITE.

You can use system variables and functions in your programs. Their names always start with (Quad) to distinguish them from other function and variable names.

System commands

Again, these are part of the APL system but aren't part of the APL language itself and they vary between APL dialects. However, the most crucial ones are available in all APL dialects.

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

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.

Files

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 or databases to share data between users.

When you do need to work with files, APL has the facilities for handling them.

Error handling

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.

Syntax

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 ← ⌈1000,3×4÷22+QTY

There are some common sense rules about spacing. These, and the few other syntax rules that exist, should be covered in the documentation for your APL.


CategoryAboutApl

LearnApl/AplOverview (last edited 2017-02-16 19:35:17 by KaiJaeger)