How to write a Python function for MARPLE¶
Every function called through ⌶ must follow this contract:
- Accept one
APLArrayargument (monadic) or two (dyadic, left then right) - Return an
APLArray
Monadic example¶
from marple.arraymodel import APLArray
def double(right: APLArray) -> APLArray:
data = [x * 2 for x in right.data]
return APLArray(list(right.shape), data)
Save this as mymodule.py somewhere on your Python path, then call it:
Dyadic example¶
from marple.arraymodel import APLArray, S
def power(left: APLArray, right: APLArray) -> APLArray:
base = left.data[0]
exp = right.data[0]
return S(base ** exp)
Error handling¶
If your function raises an exception, MARPLE wraps it in a DOMAIN ERROR. Return meaningful error messages in your exceptions to help users debug.
See also: Using I-Beam, Wrap a Python library