aplnb

An IPython magic for Dyalog APL

APACHE-2.0 License

Downloads
226
Stars
2
Committers
1

Using apl magics

aplnb adds %apl and %%apl functions to Jupyter and IPython, which exectute expressions in Dyalog APL.

Installation

First, install Dyalog APL. Dyalog provides a basic license for free. Once Dyalog is installed, install aplnb with:

pip install aplnb

Once that’s complete, you can install the magics to all IPython and Jupyter sessions automatically by running in your terminal:

aplnb_install

Usage

After first running an apl magic in a notebook, the APL language bar by Adám Brudzewsky is automatically added to the current page. (There is one change to Adám’s original version, which is that you can type a backtick twice in a row to enter triple backticks. To get a glyph, type backtick-q.)

You can use either a cell magic (%%ai) or a line magic (%ai). In either case the expression is evaluated and returned:

%%apl
y←⍳3
z←y×y
[1, 4, 9]
%apl 3×⍳4
[3, 6, 9, 12]
%apl ⎕A
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

You can store the value of an expression in a python variable using the line magic. Scalars, lists, and nest lists are used:

z = %apl z
print(z)
[1, 4, 9]

To avoid having the expression returned and/or displayed, end the last line with a ;.

%%apl
a←2 2 ⍴ ⍳4;

You can print from cell magics using the standard APL ⎕ glyph:

%%apl
⎕←a;
1 2
3 4

To use numpy, just pass the result of %apl into np.array:

import numpy as np
a = %apl a
np.array(a)
array([[1, 2],
       [3, 4]])

Learning APL

To start learning APL, follow the 17 video series run by Jeremy Howard, and have a look at the study notes.