APL Programming Language: A Complete Guide for Beginners

apl programming language

Open any APL program for the first time, and it’s as if someone poured a box of math symbols on the screen. Fine, it’s fair enough, that’s what it is. But, APL still lives, and it’s quietly executing in banks, insurance companies and data departments that want to process vast amounts of numbers in a hurry.

Then where did it come from? It began in the late 1950s as a way to clearly communicate math ideas to the blackboard, and was developed by Kenneth Iverson, a Harvard mathematician. The original idea wasn’t that it would be a programming language. Later, IBM converted his notation into actual working code, and the rest is history!

In this guide, you’ll learn what APL is, how the symbols function, a few simple examples, and where people use APL. At the end, you’ll know whether or not it’s worth your time.

What Is APL Programming Language?

APL’s name is quite modest given the weirdness: “A Programming Language”. It is fundamentally an array based language. Just that it’s constructed to operate on whole lists and grids of numbers at once, rather than poking individual values from them, like most languages.=

It’s a short and interesting history. The notation was invented by Kenneth Iverson in the 1960s and implemented as a working system by IBM. Modern versions such as Dyalog APL or GNU APL can be executed on a conventional computer today.

What is so special about it? Primarily in your mind. In the Python programming language, the sum of a list is obtained by writing a loop. There are two symbols that do all of the work in APL. Very bizarre at first, but satisfying once you get it.

APL Programming Language Overview

Big idea: Think in arrays for APL. With a whole list or table, you consider it as a unit and operate on it en masse. After getting used to this, a lot of code that you would normally write in 10 lines becomes 1 line.

The difference will be apparent to anyone who has used Python, R or C before. Those languages have a heavy dependence on loops and a lot of words typed out. APL avoids most of it. You write expressions based on short symbols, and the language takes care of the looping part. Rather than telling the computer every step, it’s about telling it what you want.

APL is also an interpreted and interactive language. You enter a statement, press Enter and immediately view the outcome. That is perfect for exploring, experimenting, or playing around with data. It’s sort of like operating a very advanced calculator.

Where it can be run, there are a few options:

  • Dyalog APL: the most popular modern version, with a free edition for learning
  • GNU APL: Open Source and suited for tinkerers.
  • TryAPL: no install necessary, you can try programming in a browser.

For those who are just inquisitive, begin with TryAPL. It should take about a minute to get going.

Also Read: If you’re still deciding which language to learn first, check out our guide on the best programming languages for data science to compare your options. 

Key Features of APL Programming Language

There are a few things about APL that are truly unique from what you’ve come across. Let’s take them, one at a time.

See also  17+ Electrical Project Ideas For Engineering Students In 2023

1. Array-oriented processing: In APL, all objects are arrays. Whether it’s a single number, a list, a table, or even a very complex block of data with lots of layers, they’re all the same. So if you add 5 to something, it’s just added to each value contained in it. No loop needed.

2. Short, symbolic syntax: Unlike languages such as FORTRAN or SUM, APL’s symbols are short words. In other languages one character can be used for what takes a full line of characters. At first it looks frightening, but once you have grown accustomed to it you don’t mind anymore.

3. Built-in math functions: Some of the things included are sorting, reversing, finding sums, etc., and matrix work. No need to import a library or to write them yourself.

4. Interactive environment. You enter text, click enter and receive an answer immediately. Perfect for experimentation and learning along the way.

5. Implicit looping (rank and scalar extension): APL is technical in that respect, but simply means that APL will loop over your data for you. What you say, it does.What you say, it does it without saying anything.

6. Tacit programming: This is a slightly more complicated one. Functions can be written without ever naming the data that they act upon, thus maintaining a very compact code. It can be omitted at this stage for beginners.

APL Programming Language Symbols Explained

To be honest, the first thing that everyone notices about APL are the symbols. They’re also the one reason why people fall in love or run away. However, there’s a reason to have them. Iverson intended APL to be a notation for mathematics, and each of its symbols represents a single clear concept. After becoming familiar with the meaning of a symbol you can read it quicker than a long string of words.

These are some of the most frequently used ones:

Symbol Name What it does 
⍳ Iota Makes a list of numbers. ⍳5 gives you 1 2 3 4 5 
⍴ Rho Reshapes data or tells you its shape. 2 3⍴⍳6 makes a 2 by 3 table 
+/ Reduce (sum) Adds up everything in a list. +/1 2 3 gives 6 
⌽ Reverse Flips a list backwards 
⍋ Grade up Gives the order you’d need to sort a list from smallest to largest 
∘.× Outer product Multiplies every item in one list by every item in another, like a times table 

What can be confusing to the beginning programmer is the fact that the same symbol may be used for two purposes. It depends on whether or not there is something on its left. If a function has a single argument (right-hand side), then it is monadic. It is dyadic in its form when it takes two (one on each side).

A shape can be described by a word by itself, like ⍴, which will tell you the shape of something. However, add a number to its left, and it will change the structure of your data to become that number. Two meanings, one symbol. It may sound crazy, but that’s how subtracting with – works too: 8-5 subtracts and -5 flips the sign.

Yet another quirk: APL is reading from right to left, not left to right. So 2×3+4 means “add 3 and 4 first, then multiply by 2.” It’ll stump almost anyone when they start with it, so don’t worry if it seems like it’s backwards.

How to type APL symbols

This is the one that everyone is afraid of, but it’s not so hard to do:

  • TryAPL: Can use a touch screen as a keyboard (no memory required)
  • Dyalog IDE: allows you to type symbols with the prefix key, and displays a keyboard layout.
  • Keyboard layouts: you can get an APL layout for your computer and switch to it when required

APL Programming Language Examples

Words and phrases can only take you so far with regard to reading. The kicker is when you’re running something. Here are five small examples you can use in TryAPL to play with: I’ve included a brief python version next to each one, for comparison.

See also  51+ Innovative Image Processing Projects Using Python In 2024

Example 1: Making a sequence

⍳10

Result: 1 2 3 4 5 6 7 8 9 10

That’s it. One symbol and one number. You would write a line like this in Python: list(range(1,11)). APL is not hard, its shorter. 

Example 2: Sum and average

data ← 4 8 15 16 23 42
+/data
(+/data)÷⍴data

Result: 108 for the sum, and 18 for the average.

The +/ is used to add all together. The average is the total divided by the number of items. Quick note: just note that the length of a list is given by ⍴data but the results is a list containing one element, but this is okay here. This would be written as sum(data) / len(data) in Python. 

Example 3: Turning a list into a table

3 4⍴⍳12

Result: 

1  2  3  4
5  6  7  8
9 10 11 12

In this case, ⍳12 is the numbers 1 through 12, and 3 4⍴ is the 3 rows and 4 columns. In Python, it would require a nested loop or using NumPy. 

Example 4: Multiplication table

(⍳5)∘.×⍳5

Result: 

1  2  3  4  5
2  4  6  8 10
3  6  9 12 15
4  8 12 16 20
5 10 15 20 25

The one that always elicits the “wait, really?” from novices. The outer product is the product of each element of the first list times each element of the second list. That’s two loops in Python and it takes a bit of code. 

Example 5: Sorting data

scores ← 72 95 60 88
scores[⍋scores]

Result: 60 72 88 95

Remember ⍋ from earlier? It returns an order to sort the list. Then we select items from scores in that order. In Python, it’s just sorted(scores); it’s actually a little cleaner. Not all tasks are shorter in APL. 

What Is APL Programming Language Used For?

APL is not really a language that you would use to develop a website or mobile app. It is best suited for any situation where there are a lot of numbers, complex mathematics, and a need for a quick response. These are the top locations of occurrence.

1. Finance and insurance: It’s here that APL has remained steadfast. It is applied by banks, trading companies and insurance companies in the fields of risk modelling, pricing and actuarial analysis. These positions include massive tables of data and formulas which are frequently modified, and APL allows analysts to quickly write and modify these tables. 

2. Data analysis and statistics: The default for APL data is an array, so data-related operations, such as finding averages, sorting, grouping, matrix work, seem natural. You’ll appreciate it if you’ve ever had to deal with a long list of loops or a messy spreadsheet.

3. Scientific and mathematical computing: APL was originally created for math, and so is appropriate for simulations, modelling, and research. Scientists can type an idea nearly as they’d type it on paper.

4. Machine learning prototyping: Neural networks are basically array math, so they can be written in a surprisingly few lines of APL. Not a typical production ML, but some people draw with it to quickly jot down ideas.

Real-world use

The most popular modern version is by a company called Dyalog whose customers include finance, insurance and research groups, it says. Some of these companies have been operating APL systems for years and years, and they still continue to operate them because the code is still working and they can change it very quickly.

So no, it’s not an attempt to compete with Python. It’s more of a specialised tool. The APL programming language can still write a few lines that other languages need to write a page.

Advantages and Limitations of APL Programming Language

APL is like any tool—it’s wonderful for some things, and it’s aggravating for others. Let’s see both sides before entering into something.

Advantages

1. You write less code: This is the mega one. An APL expression can often be a single line of code in another language.In other languages, a loop and a few lines of code may be one short APL expression. The fewer lines of code, the fewer spots for bugs.

See also  How Long Does It Take to Learn Code From Scratch?

2. Fast to build and test ideas: It’s interactive so you can experiment, watch the outcome and adjust it immediately. It’s a time-saver for analysts who need to dive into the data without delay.

3. Powerful array operations: They have all the tools of the trade—sums, sorting, reshaping, matrix math—right there. To perform simple numerical calculations, no additional libraries are required.

4. It changes how you think: If you don’t use APL at work, it will help you think more about data as a whole chunk than one item at a time. Many claim that it also enhanced their Python or R writing skills.

Limitations

1. The learning curve is real: It takes a bit of a while to get back to being normal with the symbols, with reading from right to left, with the whole array mindset. You will experience some ups and downs for a few weeks.

2. Symbols can be hard to read: Once you know them, short code is lovely. However, after returning to your own code after a month or even other peoples’ after a month is over, it can feel like a puzzle. Detailed feedback is very much appreciated.

3. Smaller community: There are many less tutorials, forum answers and pre-made libraries than there are for Python. There is support for those who are stuck, but it may require digging.

4. Fewer job openings: Yes, there are real jobs that call for APL usage, primarily in finance, but not quite as many as Python or Java or SQL.

You can try APL right in your browser on TryAPL, a free site with a clickable keyboard for the symbols. 

How to Get Started with APL Programming Language

The first time you start out in APL, it’s a little daunting, mostly due to the symbols. But the actual setup is easy, and in a few minutes you should be running code. Here’s a simple way to go about it, step by step.

Step 1: Try it in your browser first

Wait until you have the correct specs before installing anything. Go to free site TryAPL and type and run APL code immediately. The keyboard is displayed on the screen and is clickable, so you won’t need to memorize the symbol positions. Simply press and play and watch what happens.

Step 2: Play with the basics

Begin with the small things we’ve previously discussed. Type ⍳10, try +/1 2 3 4, and mess around with ⌽ to flip a list. Don’t be overwhelmed with information. You’re only feeling out its behavior right now.

Step 3: Install a proper version

When you have fun with it, establish something on your own computer. The most popular is Dyalog APL, which also has a free version for learning. For those who prefer open source tools, GNU APL is another possibility. One provides you with a more fully featured environment than the browser.

Step 4: Learn from good resources

There aren’t as many APL tutorials as there are for Python, but the good ones are really good. The following are some places to check:

  • Dyalog’s own learning pages: they have tutorials and videos made for beginners
  • APL Wiki: a handy reference for symbols and ideas
  • Books and online courses: look for courses and books that are accessible for beginners, and read reviews before making a purchase.
  • Community forums and chat groups: the APL crowd is small but friendly and are fond of assisting newbies

Step 5: Build a few tiny projects

You can read all you want; reading doesn’t make you smart. You will learn faster by creating things, preferably silly ones. A few ideas:

  • A grade calculator which calculates highest and average grades
  • Multiplication Table – Any size you choose
  • A simple loan or saving calculator.
  • A script designed to sort and summarise a data set that is small

Keep them small. If it is more than an hour it is probably too large for now.

Step 6: Stick with it for a few weeks

The first week is typically the most difficult. All this will sound like gibberish, and you’ll likely mess up with the correct order from left to right a lot. That’s normal. Practice 20 or 30 minutes a day and most people will begin to feel comfortable in a few weeks.

Final Thoughts

Hence, here’s the APL programming language in a nutshell. It is unusual, it is compact and it asks you to consider data in a newly and completely different way. It won’t be your sole solution, but it’s okay. However, for tasks with more numbers, like in finance and data analysis, it still manages to hold its own after all these years.

Is there any relevance to it now? Yes, but in a more niche fashion. Even if you don’t write APL at your job, understanding some APL can help you think about arrays and data in other languages!

If you’re curious, take 10 minutes to play with TryAPL, if you haven’t yet done so. If you ever find yourself in a jam while solving a programming or statistics problem, Statanalytica’s team is here to help! Try the APL programming language, you may be surprised!

FAQs

1. Is APL still used today?

Yes, it is. The Business Process Management (BPM) applications used in finance and insurance are still in use, and Dyalog continues to release updates of its version. It’s a pastiche language in the present, but not one that has ceased to be.

2. Is APL hard to learn?

At the beginning it can be challenging due to the symbols and the right to left reading direction. However, most people tend to get comfortable after a couple of weeks of practice.

3. How is APL different from Python?

Python is word-based and iterates over loops, APL is short symbol-based and works with whole arrays. APL code is more compact, Python is easier to read.

Leave a Comment

Your email address will not be published. Required fields are marked *