“In the near future, the cost of computer hardware required for launching and operating the program will be negligible compared to the cost of a programmer’s work, so it makes sense to develop programming languages that, although more demanding of computer resources, allow you to minimize the amount of code,” Dr. Jim Brown, who led the APL group of IBM developers in the mid-80s, reasoned like this. Well, his predictions came true only in part. Now APL is used, and quite successfully for programming financial and scientific calculations, it is included in the .NET platform and in the TIOBE Index as of November 2010 it occupies the 33rd place (rating 0.366%). APL really allows you to minimize the amount of code, and it is easy and pleasant to program on it, only its syntax is so unlike any other popular programming language that it scares most "potential fans". I will try to acquaint you with APL more closely, the language is quite useful, and, in spite of frightening at first glance "carp", is logical, beautiful, and for programming mathematical calculations and operations with large data arrays it is also the best choice of development tools.
So, APL, - the abbreviation is deciphered very simply: A Programming Language. The idea of the language came from Kenneth Iverson (Kenneth E. Iverson) in 1957 during his work at Harvard University, and found its realization during his work at IBM in 1964. The peak of using APL falls in the mid-80s, when there were many versions of the language and dialects, including those for microcontrollers. At some point, even Microsoft Corporation was planning to release its version of APL, but for unknown reasons, this release did not take place. In the early 80s, a new version of the language appeared - APL2, which was created by the IBM development team under the leadership of Dr. Jim Brown. This version became the basis of the modern APL.
Now there are about a dozen different APL interpreters. The main ones are Dyalog APL, APL Now and MicroAPL, all three work with Windows, Unix and Linux, and the latter with MacOS (I’ll continue to give examples using Dyalog APL, besides, students can download this interpreter for free from the Dyalog website: dss .dyalog.com / edu ). ')
Since the APL environment uses many non-standard characters, a special keyboard layout is used for development. In the latest versions of Dyalog APL, special characters have already been placed directly on the instrument panel, and they are easy to select by simply clicking on the desired character. So, why do we need all this? The main features and advantages of the language are the following: 1. Cross-platform implementations.
2. Calculations take place from right to left, and the calculated result is assigned to the function on the left. I will give an example:
3. The amount of code is minimized due to the use of special characters, and the fact that all operations can be performed directly above the array, i.e. no need to use loops. For example, create an array, find the sum of all array elements, find the length of the array, and then increase each array element by 1 + the number of the array element.
Thanks to these rules, APL actually allows you to implement any function in a single line of code. One friend realized Mandelbrot set on APL, and here you can download the implementation of the famous game “Life”, of course, also with one line of code.
Another huge plus is the ability to work with large matrices. Clients who use our software (and clients are investment banks, pension funds, banking alliances) often have data in matrices of 100,000 dimensions along one axis. APL allows you to perform various mathematical operations on such matrices without loss of performance.
Cons, of course, are also present. The main one, as already mentioned more than once, is an unusual syntax. For a long time, APL was generally considered “write-only language”, because it is rather difficult to understand written code. Nowadays, only a small part of the language features is used, so it is possible to do with a few of the most important characters, and generally encapsulate the APL code inside the .Net libraries.
Initially, APL was a functional-modular programming language, although modern APL supports OOP, but writing a fully object-oriented code will not be very easy and readable to put it mildly. However, it is worth bearing in mind the fact that the ability to create complex objects with the language is supported. In principle, modern APL allows you to create a graphical interface (God forbid you do this), and from the pleasant: it supports XML and lambda expressions.
Let me give you some more examples so that you can feel the language. APL provides very powerful mechanisms for working with arrays and matrices. Array elements can be of any type, arrays can be of any nesting level, and you can easily get to any element of the array. Create a 10 by 10 matrix and fill it with elements from 1 to 100. The standard address to the rows of the matrix is:
Now create an array of 3 elements: numbers, strings, and our matrix. We can easily reach any element of the array. Let's change the second letter in the row and the last element of the matrix (only the array has changed, the mat matrix has not changed).
To create a function, simply enter its name and double click on it with the mouse - the function will open in a separate window. All that goes to the left and right of the function name is the arguments, the result is what goes to the left of the assignment symbol. The result is returned in a variable with the same name, which is indicated in the first line. In APL, the function signature is only its name. I create a function that takes one argument and returns its increment.
Separately worth noting debugger APL. You can change the values of variables and move along the stack directly at runtime, which is good news. It is only necessary to switch from a mode to an editing mode. I change the variable a to 1 before executing the last line of the function, to the right is the Watch window in which the value of the variable res:
You can show many examples, but the easiest option is to download Dyalog APL and try it yourself. At the same time familiarize yourself with the standard features represented by the characters. When you hover over a symbol, information appears about its function and use.
The language analyzer checks the entered string from right to left until it meets the first function (symbol). Further checks whether there are arguments to the left of the function. If there are no arguments, then the symbol is used in its single value (monadic), if there are arguments on the left, then the value dyadic is used. Example: this symbol either rounds up or selects the maximum of two elements.
I think this information should be enough for you to be able to independently get used to the language. In conclusion, I can advise a few more video tutorials.
I hope I managed to interest you, because it seems unfair that there are no Russian-language articles about APL and in general it is completely unpopular with us. And, of course, I will try to answer your questions and / or comments.