The APL Language
APL began as a notation invented by Kenneth E. Iverson, a professor at Harvard University, to teach courses on automatic data processing – a precursor to modern computer science.
The APL Approach
It was later implemented as a programming language, initially by IBM and then many others and has evolved over the years. Dyalog APL includes many modern conveniences which anybody learning computer programming these days will be familiar with, such as if-else and for-while control structures, object-oriented features such as classes and namespaces, and anonymous lambda functions.
Its concise syntax and focus on collections of data (arrays) makes it very powerful. Instead of breaking problems down into tiny steps, APL encourages you to think in terms of working on entire data structures at once, so you can express complex algorithms in remarkably few lines of code. Many programmers find that once they embrace APL thinking, they discover solutions that would be cumbersome in traditional languages.
Concise
Simple syntax and symbols used to represent common operations on data allow users to write and adapt short and elegant expressions for all kinds of purposes.
Average (Mean):
(+⌿÷≢)3 1 4 1 5
2.8 Windowed moving average (window size: 2):
2(+⌿÷⊣)3 1 4 1 5
2 2.5 2.5 3 Weighted average:
weights ← 1 3 5 4 2
values ← 3 1 4 1 5
weights (+.×÷+/⍤⊣) values
2.666666667
Expressive
Common patterns in APL can be applied in many use cases. Conversely, there are often many ways to tackle the same problem. The small code size makes for a low cost to trying several approaches and seeing what works best for your particular application.
A windowed plus-reduction gives the sum of each set of (in this case, three) consecutive numbers:
3+/3 1 4 1 5 9 2 6 5 3 5
8 6 10 15 16 17 13 14 13 A windowed catenate-reduction returns each set of three consecutive elements as a list of lists:
3,/3 1 4 1 5 9 2 6 5 3 5
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│3 1 4│1 4 1│4 1 5│1 5 9│5 9 2│9 2 6│2 6 5│6 5 3│5 3 5│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ A less-than-reduction for windows of length 2 detects windows where the first element is 0 and the second element is 1, thus locating the first 1 in each consecutive group of 1s in a Boolean array:
1,2</' '≠'mark the start of each word'
1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 The @ (at) operator applies the uppercase function (1⎕C) to locations where a letter follows a blank:
1⎕C@(1,2</' '∘≠)'title case text'
Title Case Text
Performant
Often completely branchless, APL expressions present a high degree of mechanical sympathy ideally suited to SIMD processing. APL can offer high programmer efficiency, as well as all-out execution speed by leveraging modern processors with dedicated vector-oriented instructions.
Which are vowels (the letters a, e, i, o, and u)?
'aesthetic'∊'aeiou'
1 1 0 0 0 1 0 1 0 Remove vowels (that is, select elements of text that are not members of the list of vowels):
text←'this text is made of characters'
text⌿⍨~text∊'aeiou'
ths txt s md f chrctrs Remove interior vowels (that is, select elements that are not both vowels and in the middle of a group of three non-spaces?):
text←'can you read this?'
text⌿⍨(0,0,⍨3∧/' '≠text)⍲text∊'aeiou'
cn yu rd ths? Make vowels uppercase (that is, map from a list of lowercase vowels followed by the text itself, to a similar list which begins with the list of uppercase vowels):
text←'uppercase vowels'
('AEIOU',text)[('aeiou',text)⍳text]
UppErcAsE vOwEls
Simple
Primitive functions and operators are represented by symbols that mnemonically suggest their meanings. For example:
For example:
≢'apples'
6
3↑'apples'
app
3↓'apples'
les
⌽'reverse'
esrever
3⌽'rotate'
aterot
⌈3.141
4
3⌈5
5 Dyalog APL
Dyalog is a modern, batteries-included implementation of APL. The Dyalog interpreter has been tuned for high performance in common use cases.
The interpreter comes with a wide range of features to facilitate effective application development, and allows you to mix-and-match different programming paradigms to tackle different problems and express ideas naturally at different levels of your application. Although a compiler written in APL or a financial calculator might benefit from a linear data-flow pipeline, a business application can utilise structured programming techniques, with core computations leveraging the high-performance, mathematically-oriented primitive functions and operators.
Dyalog is well suited to exploration of data and algorithms. Its carefully chosen set of primitive functions and operators, together with a built-in standard library in the form of system functions, can be combined to solve a wide range of problems across a variety of domains. It is particularly appropriate for data cleaning, preparation and format conversion in custom, bespoke, irregular or unusual data sources. Dyalog’s concise, expressive syntax makes it well-suited for involving subject matter experts in code development and review, and its flexibility is valuable when algorithms are still evolving or data structures are large, irregular, or multi-dimensional.
Tools are available at both the built-in language level and as importable utilities to help with all kinds of tasks from reading and writing data from external data sources such as files, databases and the internet as well as converting between data formats and interfacing with non-APL systems.
Language Extensions
- Sort any array with Total Array Ordering
- Object-oriented features such as namespaces and classes
- New and extended primitive functions such as where and interval index (⍸), index-of (⍳)
- Operators for common usage patterns including the power operator (⍣)
- Fast aggregation using the key operator (⌸)
- System functions for easy data import and export such as ⎕CSV, ⎕NGET, and ⎕NPUT
- Dfns, that is, lambda-style functions for functional programming
Connectivity and Integration
- Provide and consume web services
- Read, write and manage SQL databases
- Create compiled libraries (.dll, .so, .dylib), and use those written in C or other languages
- Use and create .NET assemblies to interoperate with C# and other .NET languages
- Talk to live-running Python and R systems
- Interface directly with Microsoft Excel and other Office products for automation
Data-parallel and Asynchronous Programming
APL’s array-oriented primitive functions and operators are inherently data-parallel, and take advantage of SIMD optimisations on compatible hardware.
Dyalog also provides constructs for asynchronous programming with the spawn operator (&) for green threads, and isolates or .NET tasks to utilise multiple processes.
You’ve seen what makes APL concise, expressive and powerful. The best way to understand it is to start using it. Follow our Quick Start Guide to get up and running, or explore our learning resources to find the path that suits you.
Adám Brudzewsky, Head of Language Design
For those who like to learn by doing, there are interactive tutorials, exercises, and resources that enable you to develop your knowledge of Dyalog APL at your own pace.
If you like exploring reference material, there are guides that break down concepts into manageable lessons and websites that can expand your understanding.
Prefer to see things in action? Our video tutorials provide clear explanations and demonstrations of various APL concepts, all presented by experienced APL programmers.
APL Language
APL began as a notation invented by Kenneth E. Iverson, a professor at Harvard University, to teach courses on automatic data processing – a precursor to modern computer science.
It was later implemented as a programming language, initially by IBM and then many others and has evolved over the years. Dyalog APL includes many modern conveniences which anybody learning computer programming these days will be familiar with, such as if-else and for-while control structures, object-oriented features such as classes and namespaces, and anonymous lambda functions.
Its concise syntax and focus on collections of data (arrays) makes it very powerful. Instead of breaking problems down into tiny steps, APL encourages you to think in terms of working on entire data structures at once, so you can express complex algorithms in remarkably few lines of code. Many programmers find that once they embrace APL thinking, they discover solutions that would be cumbersome in traditional languages.
Concise
Simple syntax and symbols used to represent common operations on data allow users to write and adapt short and elegant expressions for all kinds of purposes.
Average (Mean):
(+⌿÷≢)3 1 4 1 5
2.8 Windowed moving average (window size: 2):
2(+⌿÷⊣)3 1 4 1 5
2 2.5 2.5 3 Weighted average:
weights ← 1 3 5 4 2
values ← 3 1 4 1 5
weights (+.×÷+/⍤⊣) values
2.666666667 Performant
Often completely branchless, APL expressions present a high degree of mechanical sympathy ideally suited to SIMD processing. APL can offer high programmer efficiency, as well as all-out execution speed by leveraging modern processors with dedicated vector-oriented instructions.
Which are vowels (the letters a, e, i, o, and u)?
'aesthetic'∊'aeiou'
1 1 0 0 0 1 0 1 0 Remove vowels (that is, select elements of text that are not members of the list of vowels):
text←'this text is made of characters'
text⌿⍨~text∊'aeiou'
ths txt s md f chrctrs Remove interior vowels (that is, select elements that are not both vowels and in the middle of a group of three non-spaces?):
text←'can you read this?'
text⌿⍨(0,0,⍨3∧/' '≠text)⍲text∊'aeiou'
cn yu rd ths? Make vowels uppercase (that is, map from a list of lowercase vowels followed by the text itself, to a similar list which begins with the list of uppercase vowels):
text←'uppercase vowels'
('AEIOU',text)[('aeiou',text)⍳text]
UppErcAsE vOwEls Expressive
Common patterns in APL can be applied in many use cases. Conversely, there are often many ways to tackle the same problem. The small code size makes for a low cost to trying several approaches and seeing what works best for your particular application.
A windowed plus-reduction gives the sum of each set of (in this case, three) consecutive numbers:
3+/3 1 4 1 5 9 2 6 5 3 5
8 6 10 15 16 17 13 14 13 A windowed catenate-reduction returns each set of three consecutive elements as a list of lists:
3,/3 1 4 1 5 9 2 6 5 3 5
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│3 1 4│1 4 1│4 1 5│1 5 9│5 9 2│9 2 6│2 6 5│6 5 3│5 3 5│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ A less-than-reduction for windows of length 2 detects windows where the first element is 0 and the second element is 1, thus locating the first 1 in each consecutive group of 1s in a Boolean array:
1,2</' '≠'mark the start of each word'
1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 The @ (at) operator applies the uppercase function (1⎕C) to locations where a letter follows a blank:
1⎕C@(1,2</' '∘≠)'title case text'
Title Case Text Simple
Primitive functions and operators are represented by symbols that mnemonically suggest their meanings. For example:
≢'apples'
6
3↑'apples'
app
3↓'apples'
les
⌽'reverse'
esrever
3⌽'rotate'
aterot
⌈3.141
4
3⌈5
5 Dyalog APL
Language Extensions
- Sort any array with Total Array Ordering
- Object-oriented features such as namespaces and classes
- New and extended primitive functions such as where and interval index (⍸), index-of (⍳)
- Operators for common usage patterns including the power operator (⍣)
- Fast aggregation using the key operator (⌸)
- System functions for easy data import and export such as ⎕CSV, ⎕NGET, and ⎕NPUT
- Dfns, that is, lambda-style functions for functional programming
Connectivity and Integration
- Provide and consume web services
- Read, write and manage SQL databases
- Create compiled libraries (.dll, .so, .dylib), and use those written in C or other languages
- Use and create .NET assemblies to interoperate with C# and other .NET languages
- Talk to live-running Python and R systems
- Interface directly with Microsoft Excel and other Office products for automation
Data-parallel and Asynchronous Programming
&) for green threads, and isolates or .NET tasks to utilise multiple processes. CALL TO ACTION HERE
Something like “Get Started Now” or “Learn Dyalog APL“.