| 1 |
|
| 2 |
GNU APL can be compiled as a Python module. |
| 3 |
The basic build procedure is this: |
| 4 |
|
| 5 |
./configure --with-python [ other ./configure options ...] |
| 6 |
make |
| 7 |
sudo make install |
| 8 |
|
| 9 |
This installs a shared object file named 'libgnu_apl.so' in the place where |
| 10 |
GNU APL installs its libraries (typically /usr/local/lib/apl or |
| 11 |
/usr/lib/apl) |
| 12 |
|
| 13 |
The shared object file must then be copied to the directory where Python |
| 14 |
keeps its libraries (e.g. /usr/lib/python3.4/lib-dynload/). For example (if |
| 15 |
your Python version is 3.4, and NOTICE THE DIFFERENT NAMES OF THE .so FILES |
| 16 |
in /usr/local/lib/apl/ and /usr/lib/python3.4/lib-dynload/): |
| 17 |
|
| 18 |
sudo cp /usr/local/lib/apl/lib_gnu_apl.so \ |
| 19 |
/usr/lib/python3.4/lib-dynload/gnu_apl.cpython-34m.so |
| 20 |
|
| 21 |
NOTA BENE: The python3.4 directory in the example above could either be |
| 22 |
/usr/lib/python3.4 or else /usr/local/lib/python3.4. The rules as to whether |
| 23 |
libgnu_apl.so shall live below /usr/lib or below /usr/local/lib are somewhat |
| 24 |
dubious. If you get an error like: |
| 25 |
|
| 26 |
ModuleNotFoundError: No module named 'gnu_apl' |
| 27 |
|
| 28 |
in Python then you have picked the wrong one. |
| 29 |
|
| 30 |
After that, one can import GNU APL in Python and call Python functions |
| 31 |
provided by gnu_apl: |
| 32 |
|
| 33 |
>>> import gnu_apl |
| 34 |
>>> gnu_apl.exec("4 4⍴1+2") |
| 35 |
3 3 3 3 |
| 36 |
3 3 3 3 |
| 37 |
3 3 3 3 |
| 38 |
3 3 3 3 |
| 39 |
0 |
| 40 |
>>> gnu_apl.command(")WSID") |
| 41 |
'IS CLEAR WS\n' |
| 42 |
|
| 43 |
The output above is a mix of APL output and Python output, which is more often |
| 44 |
than not a bad idea. A better approach is to generate no APL output (i.e. the |
| 45 |
results of APL expressions should be assigned to variables and the variables ⎕ |
| 46 |
and ⍞ should not be used). Alternatively, you can change the default print |
| 47 |
behavior in Python with gnu_apl.set_display(mode). See, for example, |
| 48 |
gnu_apl.help('set_display'). |
| 49 |
|
| 50 |
After a sucessful installation you can display the documentation of all Python |
| 51 |
functions in an interactive Python session like this: |
| 52 |
|
| 53 |
>>> import gnu_apl |
| 54 |
>>> gnu_apl.help('all') |
| 55 |
|