Introducing BasedPL

releasesarray-languages

An APL-derived array language written in Rust, with bracket lists, named axes, index notation, built-in automatic differentiation, and a browser playground.

Author
Jeremy Howard
Published

BasedPL (BPL) is an APL-derived array language written in Rust, borrowing ideas from J and BQN. It comes as a standalone executable, a Python package with a Jupyter kernel, and a WebAssembly build that runs in a browser.

Array languages express whole-array math in a few glyphs, without loops or temporary variables. Older APL rules still trip up day-to-day programming. 1-origin indexing clashes with Python and NumPy, implicit stranding forces separator glyphs like ⊢ next to operators, and positional broadcasting silently aligns the wrong axes when two dimensions have the same length.

We built BPL to keep APL's glyphs and right-to-left evaluation while fixing those rough edges.

avg←+/÷≢
avg 2 4 9                                          ⍝ 5
m←[1 2 3◇4 5 6] ◇ +/⍤1 m                           ⍝ 6 15
sales←["NY" "LA";"jan" "feb"]:[1 2◇3 4]
"NY"⌷+/sales                                       ⍝ 3

Cleaner notation

Most of BPL's notation changes follow from writing lists in brackets, [a b c], as in Python and JavaScript. Bare literals still strand without brackets (1 2 3, "no" "yes"), and ◇ or line breaks inside brackets build higher-rank arrays ([1 2◇3 4]).

Spaces separate runs. Each run evaluates before its neighbours. That removes the ⊢ guard in +/⍤1 m and shows train structure in expressions like ⌊ +/÷≢ 1 2 4 (floor of the mean, 2ₓ). Positions and axes count from 0, with negative positions counting from the end, on top of BQN's based array model and leading-axis semantics. Selection is a regular function (⌷, or literal subscripts like v₁) and works on string-keyed axes as in "NY"⌷+/sales. Language principles explains each rule and BPL, APL and BQN side by side compares them on real code.

Named axes, index notation and autodiff

Positional broadcasting hides bugs when a batch axis and a feature axis share the same length. Adding a 2-item bias to a 2-by-2 batch silently adds the bias across batch items instead of features. When axes have names, BPL pairs them by name regardless of position:

r←["b":2 "o":2]ρι4ₓ ◇ bias←["o":2]ρ[10 20]ₓ
r+bias                                             ⍝ [10 21◇12 23]ₓ

Selection pairs axes by name as well. That is how index notation works. Tacit rank and transposes stay concise for a plain matrix product (x+.×w), while multi-head attention or strided convolutions get hard to read. With •index, you write the formula for one element using named indices and fold along a named axis (+.×⍠k). BPL contracts inner products along named axes directly as matrix products, without building the intermediate grid of products:

xu←[2 3]ρι6ₓ ◇ wu←[3 4]ρι12ₓ ◇ [b o k]←•index 2 4 3
∧/, (xu.[b k]+.×⍠k⁝wu.[k o]) = xu+.×wu             ⍝ $t

Automatic differentiation is a primitive operator, ∂. f∂X differentiates through primitives, dfns, trains, operators, records, and indexed or sliced updates. Forward mode runs for a single scalar input, and reverse mode runs for many inputs. Higher-order derivatives compose directly (f∂∂), and ∂ traces functions into replayable typed programs for training loops:

+/⊼ ∂ 1 2 3                                        ⍝ 2 4 6
p←["w":2 "b":1] ◇ {3×ω.w + ω.b}∂ p                 ⍝ ["w":3 "b":1]
×/∂∂ 2 3                                           ⍝ [0 1◇1 0]

Rust kernels, fusion and compiled loops

BPL interprets each function call once and runs whole-array work in compiled Rust kernels backed by rustymath. Elementwise and structural calls producing 65,536 or more items stay pending until a result is needed, then fuse into cache-sized single-pass blocks that read each input array once. Eligible fused float chains compile to native machine code in under a millisecond, and large calls split across CPU cores. •explain reports which calls fused, forced memory reads, or ran through a compiled loop. Performance and Computational foundations cover the evaluator, tracing, and numeric domains.

Try it

Open the browser playground or the interactive gallery to run BPL through the basedpl WebAssembly package on npm, with no local install.

For local work in Python, Jupyter, or a terminal:

pip install basedpl
basedpl-install
bpl

basedpl-install installs the Jupyter BasedPL kernel and BPL fonts, and on macOS installs a native keyboard layout. Each release also includes a standalone bpl executable on GitHub Releases for macOS on Apple silicon and Linux on x86-64 and arm64, with no Python required. Inside Python, you can use %%bpl cells in notebooks or call the Python API directly alongside NumPy. In the REPL or playground, type a backtick and a glyph name (such as `iota for ι) and run ]help + for built-in documentation. Start with Getting started for a guided walkthrough.