Skip to main content

Mini APL in Python Language Experiment. Uses APL arrays as the internal data model.

Project description

marple

Mini APL in Python Language Experiment. A first-generation APL interpreter with the rank operator, namespaces, and Python FFI. Uses APL arrays (shape + flat data) as the internal data model. Inspired by Rodrigo Girão Serrão's RGSPL and Iverson's Dictionary of APL.

Documentation

More extensive documentation is available here

Features

  • 40+ primitive functions — arithmetic, comparison, boolean, structural, circular/trig, match/tally, membership
  • Operators — reduce (/), scan (\), inner product (f.g), outer product (∘.f), rank ()
  • Rank operator(f⍤k) applies any function along any axis: (⌽⍤1) M reverses rows, (+/⍤1) M sums rows
  • From function () — leading-axis selection that composes with rank
  • Direct functions (dfns){⍵} syntax with guards, recursion via , default
  • Symbol table-aware parser — named functions work without parens: double ⍳5
  • Namespaces$::str::upper 'hello', #import directives, :: separator
  • I-beam operator () — Python FFI for extending MARPLE with Python code
  • Error handling⎕EA (execute alternate), ⎕EN (error number), ⎕DM (diagnostic message), ⎕SIGNAL
  • System variables⎕IO, ⎕CT, ⎕PP, ⎕RL, ⎕A, ⎕D, ⎕TS, ⎕WSID, ⎕UCS, ⎕NC, ⎕EX
  • Matrices — reshape, transpose, bracket indexing (M[r;c] any rank), matrix inverse ()
  • Numpy backend — automatic vectorization (73x faster for element-wise, 380x for outer product), with pure-Python fallback
  • Web REPL — browser-based REPL at http://localhost:8888/, Pico W-ready
  • Terminal REPL — live backtick→glyph input, workspace save/load, APL-style formatting
  • Script runnermarple script.marple with session transcript output
  • 426 tests, pyright strict, no external runtime dependencies

Quick start

Install uv if you don't have it, then:

uv venv
source .venv/bin/activate      # on Windows: .venv\Scripts\activate
uv pip install marple-lang
marple
MARPLE v0.3.0 - Mini APL in Python
CLEAR WS

      ⍳5
1 2 3 4 5
      +/⍳100
5050
      fact←{⍵≤1:1⋄⍵×∇ ⍵-1}
      fact 10
3628800
      double←{⍵+⍵}
      double ⍳5
2 4 6 8 10
      M←3 4⍴⍳12
      (⌽⍤1) M
 4  3  2  1
 8  7  6  5
12 11 10  9
      $::str::upper 'hello'
HELLO

Running scripts

marple examples/01_primitives.marple          # run and display
marple examples/01_primitives.marple > out.txt  # capture session transcript

Four demo scripts are included in examples/:

  • 01_primitives.marple — arithmetic, vectors, matrices, reduce, products
  • 02_dfns.marple — user functions, guards, recursion, rank operator
  • 03_namespaces.marple — system library, imports, file I/O, i-beams
  • 04_errors.marple — ea/en error handling, error codes

APL character input

If you have a Dyalog APL keyboard layout installed (e.g. via setxkbmap with grp:win_switch), you can use the Win key to type APL glyphs directly.

Alternatively, type APL glyphs using backtick prefixes — they appear immediately as you type:

Key Glyph Key Glyph Key Glyph Key Glyph
`r `i `l `w
`a `V `x `c
`- × `= ÷ `< `>
`/ `o `* `2 ¯
`q `Q `g `G
`t `y `n `N
`J `I `j `D
`B

System commands

Command Action
)off Exit
)clear Clear workspace
)wsid [name] Show or set workspace ID
)save [name] Save workspace (sets WSID if name given)
)load name Load workspace
)lib List saved workspaces
)fns [ns] List defined functions (optionally in namespace)
)vars List defined variables

Development

pip install -e .[test]
pytest
pyright src/

To run without numpy (pure-Python mode):

MARPLE_BACKEND=none pytest

Architecture

Module Purpose
arraymodel.py APLArray(shape, data) — the core data structure
backend.py Numpy/CuPy/ulab detection with pure-Python fallback
tokenizer.py Lexer for APL glyphs, numbers, strings, qualified names
parser.py Right-to-left recursive descent with symbol table
interpreter.py Tree-walking evaluator with dfn closures
functions.py Scalar functions with pervasion (numpy-accelerated)
structural.py Shape-manipulating and indexing functions
cells.py Cell decomposition and reassembly for the rank operator
namespace.py Hierarchical namespace resolution and system workspace
errors.py APL error classes with numeric codes
repl.py Interactive read-eval-print loop
script.py Script runner with session transcript output
terminal.py Raw terminal input with live glyph translation
glyphs.py Backtick → APL character mapping
workspace.py Directory-based workspace persistence
stdlib/ Standard library: string, I/O, and error handling

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marple_lang-0.3.1.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marple_lang-0.3.1-py2.py3-none-any.whl (42.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file marple_lang-0.3.1.tar.gz.

File metadata

  • Download URL: marple_lang-0.3.1.tar.gz
  • Upload date:
  • Size: 54.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for marple_lang-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4396f8bc32e108581f2fc2e3d9d629426560a8c520fc03852a726272cd989497
MD5 9aa61a1060450deb2bf1d4d84e7a699d
BLAKE2b-256 59d72bca6f15b8d93bf5a6ff5bc1842d37a916eea77164f923a52cede6ef2269

See more details on using hashes here.

File details

Details for the file marple_lang-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: marple_lang-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for marple_lang-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 79653ba6bda212c46d01c3b3ceb040c6b0cd10772cebe2fcc8135aa16ac2cb49
MD5 0b9834ae9558caddd5215c4650bd8a31
BLAKE2b-256 19dfb8d70219e0366f81d64619f092cc7f8a31f493e2fdce7277d5abd4ed96dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page