APL
1966fraglethistoricalarrayfunctionalimperative.apl
docker run --rm --platform="linux/amd64" 100hellos/apl:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →What can I add that isn't already covered by Wikipedia:
APL (named after the book A Programming Language) is a programming language developed in the 1960s by Kenneth E. Iverson. Its central datatype is the multidimensional array. It uses a large range of special graphic symbols to represent most functions and operators, leading to very concise code. It has been an important influence on the development of concept modeling, spreadsheets, functional programming, and computer math packages. It has also inspired several other programming languages.
This container builds GNU APL 1.8 from source as Alpine doesn't yet include it in their stable distribution.
Hello World
⍝ Because anything that is in quotes is printed to the terminal, a simple APL
⍝ program is just that string.
'Hello World!'Coding Guide
Code format
- Single expression or multiple lines. Your fragment replaces the default expression. A quoted string is printed when evaluated. You can use multiple statements (one per line).
Minimal fragment (copy and adapt)
'Hello from fragment!'Language / runtime
- GNU APL 1.8, run with
apl --OFF -s -f script.apl. Script mode reads the file and exits.
Output and input
- Quoted string — e.g.
'text'prints that text. - ⎕ARG — vector of command-line arguments (options after
--when invoking the interpreter). - ⎕INP B — (GNU APL) reads lines from stdin until a line matching pattern B; returns the lines read. For one line, use a sentinel line (e.g.
⊃⎕INP '%%'and pipe42\n%%).
Common patterns
- Print:
'message' - Print with newline:
'message',⎕TC[2]or multiple expressions. - Args:
(⎕ARG ⍳ ⊂'--') ↓ ⎕ARGgives application args; index into or display as needed. - Stdin (one line via sentinel): e.g.
line ← ⊃⎕INP '%%'then useline.
Caveats
- Command-line arguments must be passed after
--to the interpreter so they appear in ⎕ARG (the execution script does this). - ⎕INP reads until a pattern; for simple “one line” input, use a sentinel line in the piped input.
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=apl
(⎕ARG ⍳ ⊂'--') ↓ ⎕ARGFib
#!/usr/bin/env -S fragletc --vein=apl
⍝ First 15 Fibonacci numbers (many-line, no train)
fib ← 1 1
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fib ← fib,+/¯2↑fib
fibFizzbuzz
#!/usr/bin/env -S fragletc --vein=apl
⍝ FizzBuzz 1–15: index 1–4 from divisibility (3,5,15), pick (⍕n) or Fizz/Buzz/FizzBuzz
{((⍕⍵) 'Fizz' 'Buzz' 'FizzBuzz')[1+((0=15|⍵)×3)+((0=3|⍵)×(0≠15|⍵))+(2×(0=5|⍵)×(0≠15|⍵))]}¨⍳15Stdin Upper
#!/usr/bin/env -S fragletc --vein=apl
⍞Test
#!/usr/bin/env -S fragletc --vein=apl
⍝ Because anything that is in quotes is printed to the terminal, a simple APL
⍝ program is just that string.
'Hello World!'Times Table
#!/usr/bin/env -S fragletc --vein=apl
⍝ A small multiplication table (many-line fraglet)
⍝ Build rows and cols, then outer product.
n ← 5
rows ← ⍳n
cols ← ⍳n
table ← rows ∘.× cols
'5×5 times table:'
table
'Done.'Connections
influences