Skip to main content
APL – A Programming Language

        By Bryan Wilson
//TODO - Header
•   Short History
•   Brief APL Rundown
•   APL Details and Tools
•   Syntax
    – Data, Structures, Classes
    – Functions, Operands
    – System Variables, Functions
• Expanding APL
30 Second History
• This language is crazy
• History sheds light on why
Enter Kenneth E. Iverson




 Profession: Mathematics
    “5 is greater than 1. Look”
His Notation




Relic found in ancient Mayan ruins.
A Pointless Language
•   Entirely dynamic, highly abstract
•   Largely interpreted (line by line execution)
•   “Keywords” are symbols
•   Tacit programming
•   Short programs, probably about 1 line
•   Write-only language
How the magic happens
• Right to left evaluation, except for parens
       5 + 5
  10
       5 x 5
  25
       5 × 5 + 5
  50
       (5 × 5) + 5
  30
Time to get crazy
• Types of data are largely done for you
           1 2 3 + 5
     6 7 8
           ¼9
     1 2 3 4 5 6 7 8 9
           2 4 ½¼9
     1 2 3 4 5 6 7
     8 9 1 2 3 4 5
Stop. Demotime.
Boring APL stuff
• Specifications
  – ISO (International Standards Organization
  – APL2, by IBM
• Interpreted
  – Thus, Interpreters
     •   APL+
     •   APLX
     •   Dyalog APL
     •   VisualAPL
Interpreters
• Use workspaces, and have unique specs
  – Workspace
  – System Variables
  – System Functions
• Modes
  – Calculator mode
  – Definition mode
Simple Data
• A number
  – 24595
  – Can be decimal or negative
• A character
  – ‘s’
  – Wrapped in single quotes
  – ‘Use two ‘’ to escape the ‘’ ‘
Data Structures
• May have data, has dimensions
• Data does not have dimensions

•   Struct – 1 item, no dimensions
•   Vector- 1d list of items
•   Matrix -2D..nD list of items
•   Item can be character, number or structure
•   Data structures can have mixed data, or nested
Data and structure syntax
• To store a variable
  [name] „ [variable]
• Names can start with a letter and NOTHING
  else
• Names can have numbers and some symbols
• Don’t duplicate names
Functions
• Types
    – 0 arguments (niladic)
    – 1 argument (monadic)
       • Everything to the right
    – 2 arguments (dyadic)
       • Everything to the right
       • First item to the left
•   Can return data/data structure
•   Bucket brigade
•   Can be named like data
•   One symbol, 1-2 functions, depending on arguments
Operations
• Modify the function of…functions.
  – How functions are applied to data
• In addition to 0-2 arguments, can take 1-2
  operands
• Functions can be operands
• Can also be named like functions
Classes
• Logical grouping of data and functions
„ŒNEW CLASSNAME
[classname].[function/property]
• Can have constructors.
• Some interpreters let you use external classes
  – .NET
Alienspeak
• Arithmetic
  +, -, ×, ÷, ⌈, ⌊, |
• Algebraic
  ⍳ , ? , * , ⍟, ○, ! , ⌹
• Comparative
  <, ≤, =, ≥, >, ≠, ≡, ∊, ⍳, ⍷
• Logical
  ~, ∨, ^, ⍱, ⍲
• Manipulative
  ⍴, ≡, , , ∊, ~, ⌽, ⍉, ↑, ↓, ⊂, ⊃
Continued Mathyspeak
• Sorting
  ⍋, ⍒, ⊤, ⊥
• Miscellaneous
  ⎕, ⍞, ⋄, ⍕, ⍝, ⍎, ⌷, ⌻,¯
• Operators
  /, , ., ∘. , ¨, [ ]
Defining your own functions
• It can be done! Watch!
System Variables and Functions
• Variables
  – Easy to pick out, they start with Œ
  – Change depending on interpreter
• Functions
  – Start with a )
  – Also change depending on interpreter
Can’t cover everything!
• Can you have threads?
  – Yes. Some interpreters.
• Can you have labels?
  – In function and operation definitions.
  – This includes if/else and try/catch blocks
• Where can I learn more?
  – Classes quoted at ~$2000 per day per person
The future is J
• APL transformed to be easier to read

quicksort=: (($:@(<#[), (=#[), $:@(>#[)) ({~ ?@#))
^: (1<#)
Summary
• Simply put:
  – Dynamic
  – Abstract
  – Powerful
  – Awesome
Questions for YOU
1. ⍳9 Returns what?
  1 2 3 4 5 6 7 8 9


2. What does an operator in APL do?
  Changes how a function is applied to data


3. To create a 3 dimensional array:
  (1 2 3) ⍴ (5 4)
Questions for me?


There are three things a man must do
        before his life is done
       write two lines in APL,
   and make the damn thing run