Introduction to APL (1 of 14)
Origins of APL
APL began life as a notation for expressing mathematical procedures. Its originator, Dr Kenneth Iverson, published his notation in 1962 in a book called 'A Programming Language' from which title the name APL derives.
Subsequently Iverson's notation was implemented on various computers and did indeed become 'a programming language'.
The specification of the language was substantially enhanced during the 1980's, notably by Dr James Brown in IBM's APL2, giving rise to the term 'second generation APL' to cover those versions of APL that included the enhanced specifications.
The development of the APL language has continued in the 21st century. Whilst retaining compatibility with APL2 and Dyalog APL add object-oriented language extensions, as well as a large number of other facilities, to the language.
Some features of the language
The ability to handle generalized array data without complicated programming is one of APL's strongest points.
The language lets you define and give a name to a single item of data, a list of items, or a table of items, or indeed arrays of more dimensions. This means it's just as easy to write an instruction that adds two tables as one that adds two numbers.
The extra work caused by such an instruction is handled by APL internally. It goes through the named arrays of data, successively selecting and adding corresponding items, and it stops automatically when it finds that the items are exhausted.
Consequently there's usually no need for counts, loops or any of the mechanisms traditionally used to control such operations in other programming languages: the structure of the data effectively does this for you.
APL has a powerful repertoire of functions (i.e. operations it can perform). These include a full range of sophisticated mathematical functions and a range of data manipulative functions which can do anything from a simple sort to a matrix inversion.
These functions can be combined so that on a single line you have a series of functions interacting dynamically, one function's results forming the next function's data.
APL also has operators which modify the way in which functions are applied. This gives you a range of general purpose building-blocks which can easily be combined in a very flexible and consistent manner.
This flexibility combined with APL's ability to handle complicated data makes it a uniquely powerful language.
The syntax of most programming languages is restricted to the ASCII character set, which was originally designed for use in commercial data processing with very limited hardware, and which lacks even a basic multiply symbol. As a result, most programming languages resort to compromises such as using the asterisk symbol for multiply, and compound symbols such as <= to mean 'less-than-or-equal' or ** to mean 'power'. APL is not limited to the ASCII characters; instead, it uses a range of symbols to represent its built-in functions. This permits the APL user to carry out a wide range of programming tasks in a very concise manner.
Reserved 'words' in APL are generally easy to identify, since they are prefixed by a 'quad' symbol, turning them into 'system functions'. The symbolic nature of APL gives it an international appeal which transcends different national languages.
For many years, the use of special symbols by APL, and the special keyboards and display devices associated with them, was seen by many people as a big disadvantage of the language. Nowadays, with Unicode fonts and easy-to-use input methods, the special symbols are no longer such an issue.
Besides giving you functions that are built in to the language, APL lets you define your own. In fact, what you might normally think of as a 'program' consists, in APL, of a collection of user-written functions each of which does a part of the total task.
These functions can 'call' each other and exchange data, but each is quite separate and self-contained. This has two very useful consequences.
First, debugging is much easier since each function can be tested separately and errors are easy to isolate.
Second, it imposes a natural top-down structure on your programs.
Dyalog APL takes the traditional modularity of APL further by implementing 'object-oriented' programming concepts. The programmer using these APLs can define classes (collections of data and related program logic) and create and use instances of those classes (objects).
A special syntax unique to Dyalog APL is used for object-oriented programming.
Classes defined in .Net languages such as C# or VisualBasic.Net can be used by Dyalog APL and APL+Win.
APL is convenient to use for many reasons. In the first place, it's concise. A very few lines of APL can do a lot of work. Then it's an essentially interactive language. As you write each line or function you can try it out and get immediate feedback. It's also a fully dynamic language, which means that you do not have to specify in advance what is valid for a given data item or function; you can just use it immediately.
In addition, most APL implementations currently employ a useful concept called the workspace. This is basically a collection of the data items, functions, and classes which you set up in the course of doing a particular job.
The workspace is in computer memory while you work, making everything you want immediately accessible. It can be saved (i.e. copied on to a disc) in its entirety when you stop, and loaded back into memory next time you want to use it.
Ease of learning
APL is easy to learn in the sense that it's easy to get started. You'll be able to do simple things almost immediately.
Once started you can explore the language, discovering the functions and techniques that are of interest to you. APL supports this way of learning: it's totally consistent and does not have many arbitrary rules. And, as already said, it supplies immediate results and feedback.
What's more, because APL is different from conventional languages, it actually helps to be a computer novice!
Some professional programmers find it difficult to accept that APL can handle complicated data without loops and counts. They're unused to the APL concept of a 'workspace' in which data and code may rub shoulders. 'Type-safety' issues of data objects in other programming languages can be a distraction from the thinking and design efforts to solve the problem at hand. The dynamic datatyping of APL variables means an APL programmer can concentrate on the important concepts of their solution. APL functions are modeled on mathematical functions, rather than traditional programs and subroutines of other languages.
If you haven't programmed before, none of these questions will bother you. You'll accept the way APL does things as natural and convenient. For this reason, APL has traditionally been used by people who are not primarily computer programmers, but who need to write quite sophisticated programs in the course of their work or research - actuaries, engineers, statisticians, biologists, financial analysts, market researchers, and so on.
Unlike many programming languages, APL wasn't designed to match the ways in which a computer works internally. It was intended to help people define procedures for solving problems.
This makes it efficient for people to use, though it may give the computer a little more work to do in the process.
This is reflected in development times. You'll find you can produce a working prototype very rapidly. Thanks to the modular approach encouraged by the language, and the ease with which modules can be tested, corrected and combined, it takes little extra time to turn this prototype into the final, fully tested version.