← Back to all projects

LEARN APL DEEP DIVE

Learn APL: From Zero to Array-Oriented Thinker

Goal: To master the APL programming language and its array-oriented paradigm. You will learn to solve complex problems with shockingly concise and powerful expressions by thinking in terms of whole arrays, not loops.


Why Learn APL?

APL is more than just a programming language; it’s a tool for thought. In a world of verbose, boilerplate-heavy code, APL offers a path to clarity and precision. It forces you to see the structure of your data and to express computations as transformations on entire arrays. Learning APL will stretch your mind, make you a better problem-solver, and give you a unique perspective that you can apply in any other language.

After completing these projects, you will:

  • Read and write APL’s iconic symbolic syntax.
  • Solve problems by composing powerful primitive functions.
  • Understand the power of array-oriented thinking and abandon explicit loops.
  • Grasp higher-order functions (operators) like Reduce, Scan, and Outer Product.
  • Be able to write elegant, “one-liner” solutions to complex data manipulation tasks.

Core Concept Analysis

(Please see the detailed conceptual overview provided in the previous response for a breakdown of the APL mindset, the glyphs, and the right-to-left evaluation rule.)

The key to APL is to stop thinking about individual items (for each x in list...) and start thinking about the entire collection at once (apply function to list).

A typical problem-solving process in APL:

  1. How can I represent my data as an array (vector, matrix, etc.)?
  2. What is the final shape of the array I want to produce?
  3. Which sequence of primitive functions will transform my input array into my output array?

Project List

These projects are small, data-centric problems that are perfectly suited to APL’s strengths. The goal is not to build a large application, but to build fluency in array-oriented thinking. The best way to work on these is with an interactive APL session, like Dyalog APL or an online interpreter like tryapl.org.


Project 1: Statistical Calculator

  • File: LEARN_APL_DEEP_DIVE.md
  • Main Programming Language: APL
  • Alternative Programming Languages: K, J, BQN (other array languages)
  • Coolness Level: Level 3: Genuinely Clever
  • Business Potential: 1. The “Resume Gold”
  • Difficulty: Level 1: Beginner
  • Knowledge Area: Array Programming / Data Analysis
  • Software or Tool: Dyalog APL or tryapl.org
  • Main Book: “Mastering Dyalog APL” by Bernard Legrand

What you’ll build: A collection of short APL functions to compute basic descriptive statistics on a vector of numbers: count, sum, mean, min, max, and range.

Why it teaches APL: This is the perfect introduction to the “reduce” operator / and the most basic array primitives. You will immediately see how operations that would require a loop in other languages become a simple combination of 2 or 3 glyphs in APL.

Core challenges you’ll face:

  • Calculating the sum → maps to using the +/ (plus reduce) operator
  • Finding the count → maps to using (rho) to get the shape/size of a vector
  • Calculating the mean → maps to composing the sum and count functions
  • Finding the min and max → maps to using the ⌈/ (max reduce) and ⌊/ (min reduce) operators

Key Concepts:

  • Vectors: The basic 1-dimensional array.
  • Reduce Operator /: Inserts a function between elements of an array.
  • Primitive Functions: +, ÷, , .
  • Structural Functions: (shape).

Difficulty: Beginner Time estimate: A few hours. Prerequisites: A willingness to embrace symbols.

Real world outcome: A set of working functions in an APL session.

      V ← 10 20 30 40 50
      
      Count ← ⍴
      Sum ← +/
      Mean ← (+/) ÷ ⍴

      Count V
5
      Sum V
150
      Mean V
30

Implementation Hints:

  • The beauty of APL is that many of these are already one-liners. The mean is a great example of function composition: (+/V) ÷ (⍴V).
  • For the range, you’ll want to find the maximum (⌈/V) and the minimum (⌊/V) and then subtract them. Remember the right-to-left rule when you compose this! (⌈/V) - (⌊/V).

Learning milestones:

  1. You can calculate the sum and count → You understand +/ and .
  2. You can calculate the mean → You understand function composition and the right-to-left rule.
  3. You can calculate the min, max, and range → You understand how to apply different functions with the reduce operator.
  4. You instinctively try to solve problems by combining glyphs instead of writing a loop → The APL mindset is beginning to form.

Project 2: Conway’s Game of Life

  • File: LEARN_APL_DEEP_DIVE.md
  • Main Programming Language: APL
  • Alternative Programming Languages: N/A (It’s a classic APL showpiece)
  • Coolness Level: Level 5: Pure Magic (Super Cool)
  • Business Potential: 1. The “Resume Gold”
  • Difficulty: Level 3: Advanced
  • Knowledge Area: Array Manipulation / Cellular Automata
  • Software or Tool: Dyalog APL
  • Main Book: “Game of Life in APL” (many articles and videos online).

What you’ll build: A simulation of Conway’s Game of Life. You’ll have a function that takes a binary matrix (the “board”) and computes the next generation of the board according to the game’s rules.

Why it teaches APL: This is a legendary APL problem because the solution is breathtakingly elegant and perfectly showcases array-oriented thinking. The core logic—counting the neighbors of every cell simultaneously—is a masterclass in composing array-shifting and arithmetic operations, completely avoiding loops.

Core challenges you’ll face:

  • Representing the board → maps to using a 2D binary matrix (0s and 1s)
  • Counting all neighbors for every cell at once → maps to shifting the entire matrix in 8 directions and summing the results
  • Applying the life/death rules → maps to a single boolean expression applied to the entire neighbor-count matrix
  • Visualizing the result → maps to using (quad) character output or a simple GUI

Key Concepts:

  • Matrices: 2-dimensional arrays.
  • and (Rotate): The key to shifting the matrix. You can rotate along the first or second axis.
  • Boolean Algebra: Applying rules like (is_alive AND neighbors = 2) OR (neighbors = 3) to the whole board at once.
  • Function Trains (Tacit Programming): Writing a sequence of functions that operate on data without explicitly mentioning the data.

Difficulty: Advanced Time estimate: A weekend for the core logic, more for visualization. Prerequisites: Solid grasp of APL basics (Project 1).

Real world outcome: A function that, when called repeatedly, produces the evolving generations of a Game of Life simulation.

      ⎕← board_1           ⍝ Display the initial board
1 0 0 1
0 1 1 0
1 1 0 0

      ⎕← life board_1      ⍝ Call your function
0 1 1 0
0 0 1 0
1 1 1 0

Implementation Hints:

  1. The core of the problem is the neighbor count. To get the “east” neighbors for every cell, you can rotate the entire board one step to the left: 1 ⌽ board.
  2. To get all 8 neighbors, you can rotate the board one step in all 8 directions (N, S, E, W, NE, NW, SE, SW) and sum the 8 resulting matrices. Rotation on a diagonal involves a rotation on the first axis followed by a rotation on the second axis.
  3. Once you have a matrix of neighbor counts, the rules are a simple boolean expression. Let N be the neighbor count matrix and B be the original board. The next state is (B ∧ N ∊ 2 3) ∨ (∼B ∧ N = 3).
  4. This entire logic can be expressed as a single, beautiful, and baffling APL one-liner.

Learning milestones:

  1. You can shift the entire matrix in one direction → You understand .
  2. You can compute the neighbor count for all cells at once → You have mastered array-level transformations.
  3. You can apply the rules to compute the next generation → You understand boolean array logic.
  4. You see the elegance of the whole-array solution and laugh at the thought of using nested loops → You are an APL programmer.

Project 3: Prime Number Sieve

  • File: LEARN_APL_DEEP_DIVE.md
  • Main Programming Language: APL
  • Alternative Programming Languages: N/A
  • Coolness Level: Level 4: Hardcore Tech Flex
  • Business Potential: 1. The “Resume Gold”
  • Difficulty: Level 2: Intermediate
  • Knowledge Area: Number Theory / Set Operations / Boolean Logic
  • Software or Tool: Dyalog APL
  • Main Book: “APL 2 at a Glance” by Brown & Pakin

What you’ll build: A function that takes an integer N and generates all prime numbers up to N using the Sieve of Eratosthenes algorithm.

Why it teaches APL: Like the Game of Life, the Sieve is a classic APL problem. The solution is famously concise and relies on a different set of APL’s strengths: boolean vectors, set membership, and using outer products to generate multiples.

Core challenges you’ll face:

  • Generating a list of candidates → maps to using (iota) to generate integers from 1 to N
  • Removing non-primes → maps to using boolean masks to filter a vector
  • Finding multiples of primes → maps to using the ∘.× (outer product with multiplication) operator
  • Composing this into a single expression → maps to APL’s functional, right-to-left composition

Key Concepts:

  • (Iota): Generates an integer vector. ⍳5 is 1 2 3 4 5.
  • (Epsilon / Member of): Tests for set membership. (1 5 9) ∊ (⍳10) gives 1 1 0.
  • (Tilde / Not): Logical NOT, used to flip a boolean mask.
  • Outer Product ∘.f: The operator for creating tables of results.
  • / (Replicate): Used with a boolean mask to select elements from an array.

Difficulty: Intermediate Time estimate: A few hours. Prerequisites: Project 1.

Real world outcome: A function that efficiently generates primes.

      Sieve 20
2 3 5 7 11 13 17 19

Implementation Hints:

  1. A famous APL solution is (~R∊R∘.×R)/R←1↓⍳N. Let’s break down the thinking.
  2. ⍳N creates numbers from 1 to N. 1↓ drops the first element (1 is not prime). R← assigns this to R. So R is 2 3 ... N.
  3. R∘.×R creates the multiplication table of R with itself. This matrix contains all composite numbers that have factors in R.
  4. R ∊ R∘.×R creates a boolean vector, with a 1 for every number in R that is also in the multiplication table (i.e., is composite).
  5. flips this mask, so 1s now represent the primes.
  6. (...) / R uses this final boolean mask to select only the prime numbers from the original list R.

Your task is to build this up step by step and understand what each part does.

Learning milestones:

  1. You can generate a vector of integers → You understand .
  2. You can use an outer product to generate a multiplication table → You understand ∘.×.
  3. You can use a boolean vector and to test for membership → You understand boolean masks.
  4. You can combine these into a working prime number sieve → You have created a classic, elegant APL one-liner.

Project 4: Text Processing Utilities

  • File: LEARN_APL_DEEP_DIVE.md
  • Main Programming Language: APL
  • Alternative Programming Languages: K, J
  • Coolness Level: Level 3: Genuinely Clever
  • Business Potential: 1. The “Resume Gold”
  • Difficulty: Level 2: Intermediate
  • Knowledge Area: String Manipulation / Data Aggregation
  • Software or Tool: Dyalog APL
  • Main Book: “Mastering Dyalog APL” by Bernard Legrand

What you’ll build: A toolkit of functions for basic text analysis: a palindrome checker, a character frequency counter, and a word frequency counter.

Why it teaches APL: Text in APL is just a character vector. This project teaches you how to apply array-oriented thinking to common string manipulation tasks. It’s a great way to practice using ∘.= (outer product with equals) and the +/ operator for counting and aggregation.

Core challenges you’ll face:

  • Checking for palindromes → maps to comparing a vector with its reverse ()
  • Finding unique characters → maps to using the (unique) function
  • Counting character frequencies → maps to using an outer product ∘.= to compare all characters against the unique characters, then summing the columns of the resulting boolean matrix
  • Splitting text into words → maps to finding the spaces and partitioning the vector

Key Concepts:

  • Character Vectors: How strings are represented.
  • (Unique): Finds the unique elements in an array.
  • Outer Product ∘.=: Creates a comparison matrix. V ∘.= V gives the identity matrix.
  • (Rank) and " (Each): Alternative ways to apply functions to sub-arrays.

Difficulty: Intermediate

  • Time estimate: A weekend.
  • Prerequisites: Project 1.

Real world outcome: A set of functions that can analyze text.

      IsPalindrome 'madam'
1
      IsPalindrome 'madame'
0
      FreqCount 'hello world'
┌─┬──┐
│h│1 │
├─┼──┤
│e│1 │
├─┼──┤
│l│3 │
├─┼──┤
│o│2 │
├─┼──┤
│ │1 │
├─┼──┤
│w│1 │
├─┼──┤
│r│1 │
├─┼──┤
│d│1 │
└─┴──┘

Implementation Hints:

  • Palindrome: The logic is simply text ≡ ⌽text. The (depth / match) operator checks if two arrays are identical in structure and content.
  • Frequency Count:
    1. Let S be your string. Find the unique characters: U ← ∪S.
    2. Create the comparison matrix: M ← S ∘.= U. This is a boolean matrix where M[i;j] is 1 if S[i] equals U[j].
    3. Sum the columns of this matrix to get the counts for each unique character. The columns are on the first axis, so you need +/[1] M.
    4. Combine the unique characters and the counts into a 2-column matrix for display.

Learning milestones:

  1. You have a working palindrome checker → You understand and .
  2. You can count character frequencies → You have mastered the powerful ∘.= and +/ combination for aggregation.
  3. You can split a string into words → You are learning more advanced vector partitioning techniques.
  4. You no longer see text as a special case, but just as another array to be manipulated → You are a true array programmer.

Summary

| Project | Main Language | Difficulty | Key APL Concept Taught | |—|—|—|—| | Statistical Calculator | APL | Beginner | The Reduce Operator (/), basic primitives | | Conway’s Game of Life | APL | Advanced | 2D Array Manipulation, (Rotate) | | Prime Number Sieve | APL | Intermediate | Boolean Masks, Outer Products (∘.×) | | Text Processing Utilities | APL | Intermediate | Character Arrays, , ∘.= for counting | (From here, you could explore more advanced projects like “Matrix Multiplication” (+.× inner product), “Image Manipulation” (transforming binary matrices), or even a simple “Spreadsheet Evaluator”.)