Parsing script arguments in GNU APL (⎕ARG)

In scripting languages one often wants to run the overall script like a standalone program, with a top 'main' function, yet also allow the script to be read into the REPL for editing, testing interactively and so on.

In Python a common way to do this is by checking the __main__ variable to determine execution scope.

GNU APL has the --script switch to enable invoking a .APL file and immediately executing it. In standard UNIX fashion the -- switch is also useful to divide GNU APL arguments (those for the interpreter itself) from those intended for the script. Using these two bits of information one can do the same thing in APL:

#!/usr/bin/env apl --script --

    ⍝⍝ Whatever the script should do by default when run from shell
    ⎕←'This is an APL script'

⍝ Parse args & run 'main' if not in REPL mode
⍝ in REPL mode, ⎕ARG[1] is the script path itself
⍝ (Recalling that by default, ⎕IO = 1)
    args←(⎕ARG⍳⊂"--")↓⎕ARG ⍝ Drop all args up to and including "--"
    →(~(⊂'--script')∊⎕ARG)/0 ⍝ If "--script" not present, quit to allow REPL
    ⍝⍝ ⎕←"[",args[1],"]" ⍝ (just debugging to see args)
    scriptFunction ⍎∊args[2] ⍝ in --script mode, so run default func

checkMode ⍝⍝ check the ⎕ARG vector for --script mode


A Hexadecimal Pronunciation Guide, by Robert A. Magnuson - Datamation Vol. 14, No. 1, Jan 1968

I recall discussing with a fellow CS student many years ago the topic of how speaking hexadecimal values seemed to be.. well, clunky. We both thought it strange no one had standardized a set of word stems like we have for the base ten numerals, 'teens', 'fortieth', and so on. All these years later I discovered, as it turns out, someone did. It just didn't catch on, for some reason.

An obscure article in Datamation, Vol. 14, No. 1 dated January, 1968 (alternate link, contains an article by one Robert A. Magnuson, proposing an extension to English number pronunciation for hexadecimal:

Table 2. New Names for Hexadecimal Digits
A ann
B bet
C chris
D dot
E ernest
F frost
The pronunciation of the -teen's and -ty's for the new
digits is shown in Table 3. Note that the analog of the decimal pronunciation system has been used. The new name for each new digit has been chosen so that at least one of the -teen and -ty modifications is familiar sounding.

Table 3. -Teen and -Ty Pronunciation for the New Digits

1 A annteen
1 B betteen
1 C christeen
1 D dotteen
1 E ernesteen
1 F frosteen
A0 annty
B0 betty
C0 christy
D0 dotty
E0 ernesty
F0 frosty

Now 29's successor 2A can be pronounced "twenty-
ann" without the slightest tendency to confuse it with 28.
The pronunciation of C4 is "christy-four," and that of A4
is "annty-four." There is no problem in distinguishing
between 1A, "annteen" and 18, "eighteen." And 88, 8A,
A8, and AA are easily distinguished when pronounced
"eighty-eight," "eighty-ann," "annty-eight," and "annty-

Some two-digit hex numbers, each representing one byte, appear with their new pronunciations in Table 4.

Table 4. One-Byte Strings with Pronunciation
2F twenty-frost
F2 frosty-two
5B fifty-bet
3E thirty-ernest
AF annty-frost

Some four-digit hex numbers, each representing two
bytes, appear with their new pronunciations in Table 5.

Table 5. Two-Byte Strings with Pronunciation
A01C annty christeen
1ED0 ernesteen dotty
A007 annty oh-seven
DEAF dotty-ernest annty-frost
3A7D thirty·ann seventy-dot
47F0 forty-seven frosty

The problem of the values of the added digits being off
by one is now easily solved. Merely remember the "ages"
of these new-found friends. Learn that ann is 10, bet is
11, etc. without becoming confused with the fact that A
is associated with 1, B with 2, etc.

The problems of some of the hex digits being NUMERIC
and the others ALPHA on the model 29 keypunch is solved
in the following fashion. Select a particular finger of the
left hand, say, the little finger. No other finger of the left
hand is to be used. The home position of that left little
finger is on the NUMERIC key. The right hand is used for
typing 0-9 and the (numeric) comma while the left little
finger holds down the NUMERIC key. When· A - F arise,
they are typed with the left little finger-thus ensuring
that the NUMERIC key is not depressed. Return the left
finger to the home position on the NUMERIC key imme-
diately upon finishing A-F.



APL Keyboard Sticker Set

APL Keyboard Stickers for Laptop or Desktop

APL uses a special symbol set, which presents a barrier to entry for new users. Furthermore, there don't seem to be many options to get a keyboard with APL symbols, other than expensive specialty ones (here or here), and they're for PC desktops only; so what's a laptop user to do?

I figured I'd take matters into my own hands, and produce a run of APL keyboard stickers. These match the standard APL keyboard map used by historical APL implementations as well as GNU APL and Dyalog APL. I got the shipment at end of August, 2021, and they look pretty good on my laptop. Now available on my Tindie store. Check it out!

Black vinyl keycap stickers, suitable for any standard laptop or PC desktop keyboard.

To use these you'll need to set a custom keymap. For Linux, See my post here. For Windows, see here, here and finally here.

With some trivial setup, modern systems have no issue at all supporting APL symbols. I wonder if its successor, J, would have even come to be if the APL character set wasn't seen as an impediment prior to the 2000s. As a newcomer to APL and J, comparing the two, J just seems so much harder to parse as it uses ASCII exclusively; it looks a lot more like line noise to me whereas APL encourages seeing a unique notation.


Getting Started with APL: Keyboard Mapping and Using GNU APL on Android with TermUX

APL is an under-appreciated language, pioneering many concepts that have re-appeared in almost every language since. Iverson Ghosts! Boo.

A huge hurdle for new users is those funny symbols. How does one enter them on a modern keyboard?

Wonder no longer! It's not so tough, just not documented that well on the web today. APL has its own Unicode point so all the symbols are already inside your box waiting to be used. One can even use GNU APL on an Android phone or tablet with the Hacker's Keyboard (fork for APL layout, see bottom)

One would think APL enthusiasts would have keymaps with an easy setup script to run, to encourage newcomers, but I guess not since I didn't run across any... so here's my attempt to help out any other APL-curious people out there.

BONUS: Hard-to-find APL book links. These books are out of print and insanely expensive on the used market. I manually scanned in APL2 At A Glance to save it for posterity. It really is the best introductory text for APL2.

APL2 At a Glance (English)

APL2 Ein erster Einblick (APL2 At A Glance, German)

APL2 In Depth

Adding an APL Keymap to X terminals

From X (any windowed terminal, eg. Konsole, xfce4-terminal etc.)


My preferred setup uses CAPS LOCK as the APL key:

setxkbmap us,apl -option grp:caps_switch

Try the above interactively, then put it into your .bashrc and you're good to go. If you *really* need CAPS LOCK for some reason, ALT+CAPS works.

One might also be able to define it system-wide via an xorg.conf.d/ file such as the following snippet, but I haven't rebooted yet to test it:

Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "us,apl"
Option "XkbModel" "pc104"
#Option "XkbVariant" ",dvorak"
Option "XkbOptions" "grp:caps_switch"

APL Keys For 'dfns' (lambdas)

Dyalog APL and GNU APL both use the ⍺ and ⍵ symbols for the unbound left- and right-hand variables of 'dfns' (basically lambda functions). These are standard for both APL dialects, but GNU APL also recognizes APL Functional Symbol alpha-underber, ⍶:U+2376, APL Functional Symbol omega-underbar, ⍹:U+2379 and lowercase Greek chi, χ:U+03C7.

On my Dell XPS 15 laptop, it seems using the CAPS key as the APL COMPOSE in combination with the SHIFT key does not work for the W/S/X key column. So I chose the U and C keys as alternates to yield omega-underbar and chi, respectively, instead, as Dyalog and GNU APL don't appear to have anything assigned to those with SHIFT. Modifications to my .Xmodmap are thus as follows:

keycode  25 = w W U2375 U2379
keycode  38 = a A U237A U2376
keycode  30 = u U U2193 U2379
keycode  53 = x X U2283 U03C7
keycode  54 = c C U2229 U03C7

.. and yet on my Acer Aspire, keys W and X work just fine. Weird.

To customize your X modmap (be sure you've already added the ,apl to your xkbmap above):
$ xmodmap -pke >~/.Xmodmap
$ vi .Xmodmap  ## editing the above
$ xmodmap ~/.Xmodmap   # To reload

Download my .Xmodmap keymap file here:

APL Linux Console Key Map

Download my console keymap file here:

As root,

# loadkeys APL.kmap

Almost the same as the X mapping -- CAPS LOCK and shift+CAPS LOCK are combo keys with any other key in the GNU APL mapping for APL symbols; right-ALT is APL-mode lock.

APL fonts require running within an 'fbterm' on virtual consoles, so install that first, and if you want to use APL from the console often, start 'fbterm' and 'loadkeys' from startup.

GNU APL on Android with TermUX

* open TermUX.

* Make sure you have lots of free space on your phone, as you're going to be building GNU APL from source using g++

$ apt-get install subversion

$ apt-get install g++

## might need autotools and other things as well (automake, autoconf, etc.)

$ svn checkout svn:// $ cd apl/trunk

You may have issues with network timeouts checking out the repo. If so, retry after running an svn cleanup. if you keep having trouble, fetch it on a PC Linux machine, tar+gzip the whole svn/trunk dir and then use 'scp' to just copy it to your TermUX home dir (either by installing openssh in TermUX or using an Android ssh program... but you'll have to hunt around in your phone's filesystem to find your TermUX home dir in that case...)

[Again, within TermUX]:

$ apt-get install ncurses pcre pcre2
$ cd trunk/   # wherever gnu apl source from svn was fetched
$ ./configure
$ make
$ mkdir $HOME/bin
$ cp src/apl $HOME/bin
$ export PATH=$HOME/bin:$PATH ## or set up a .bashrc or .profile with this to make it permanent

.. I might have missed a few apt-get calls required for some libraries but otherwise it did build just fine right on the phone!

Oh, and remove the svn/trunk afterwards because you'll probably be low on space :)

Finally, install the fork of Hacker's Keyboard with APL layout/language available here!


Locking Linux X Sessions without XScreensaver

 I'm currenlty using Funtoo Linux on my main laptop, and XScreenSaver was displaying a big scary warning "This version of XScreenSaver is very old! Please upgrade!". It turns out the author of XScreenSaver is, shall we say, very opinionated about downstream distros modifying this warning in any way -- though the codebase itself is allegedly free for downstream to modify, if this particular warning is touched by downstream the XScreenSaver author has insisted the program be removed entirely, said author even protesting a commonsense modification to the warning to redirect users first to the specific distribution for bug reports.

Normally I don't care so much about OSS drama, but this warning timebomb just seems antisocial. I don't care much about screensaver functionality, I just want simple session locking and the warning was bugging me. So I went searching and surprisingly there are not many other options for X session locking that aren't tightly bound to specific widget families. There's Gnome-screensaver, some built-in lock with KDE, and then there's the most neutral setup I found so far: i3lock launched from xautolock.

Depending on your desktop it takes a bit of manual setup but it's not too hard. For my XFCE4 setup, what worked for me is:

1. Create a script (remember to chmod u+x) named in ~/.config/autostart-scripts/

/usr/bin/xautolock -time 10 -locker "/usr/bin/i3lock -c 303030" &
sleep 1
pgrep xautolock && notify-send -u normal -t 4000 "xautolock active"

2. Now set that script to auto-run on login, by creating a new entry called in the XFCE4 Settings > Session and Startup, Application Autostart tab.

3. Set a keyboard shortcut eg., for Super-L, in XFCE4 Settings > Keyboard, Application Shortcuts tab, calling i3lock (use the -c option for a custom colour if you don't like the default white screen).

Log out and log in, and verify xautolock is running -- that's it!