Develop Common Lisp on Your Android Phone

Long time ago, I was wondering: is it ever possible to write Common Lisp code on my Android phone? It seems useful when I want to experiment with something on the train.

I found this application: CL REPL - Google Play.

It is actually an ECL bundled with ASDF and Slime, in a traditional Android application, as you might imagine. It is a great application, but it still lacks some useful features compared with SLIME/SLY.

I thought, since it was an ECL anyway, is it possible to use my favorite SLIME/SLY on Android?

The following content assumes that you have very basic idea about Linux shell, Common Lisp and Emacs.

Install Termux

Termux is a shell emulator on Android. According to its official website,

Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically - additional packages are available using the APT package manager.

In short, it makes it possible to use native shell commands on the Android phone!

You may need to install the following packages for the next steps.

~ $ pkg install binutils git make clang texinfo

Also, it is recommended to install some packages for better user experience, such as zsh, ripgrep etc.

Termux provides a key bar for quick input of special characters that might be hard to type, which is customizable via modifying the configuration file ~/.termux/termux.properties.

Here is what I am using:

# Ignore bell character.
bell-character = ignore
# Extra line of keys above keyboard.
extra-keys = [['TAB','CTRL','ALT','-','_','"','/',"'",'(',')']]

It is also possible to use the volume keys plus the normal keys to type special characters. See its Wiki page for more details.

Install ECL

There are 2 ways to install ECL on your Android phone: you may compile it manually, or install it directly via apt.

Compile ECL Manually

I first tried to install Roswell. Unfortunately, it did not work because Termux seemed not to support 32-bit on 64-bit machine and my phone was an aarch64 device. So I had to compile ECL manually. Please let me know if you know how to use Roswell with Termux.

First download ECL from its GitLab homepage.

~ $ git clone https://gitlab.com/embeddable-common-lisp/ecl

Then compile it using the following commands.

~/ecl $ ./configure --prefix=$HOME/software/ --build=aarch64-linux-android --enable-gmp=included
~/ecl $ make && make install

It is time to make yourself a cup of coffee now because it would take a relatively long time to finish. You deserve it!

Install ECL From Repository

Before we start, please keep in mind that the $PREFIX in the following code represents the parent path of $HOME. On my phone it is /data/data/com.termux/files.

Edit the file $PREFIX/usr/etc/apt/sources.list and add the following line:

deb https://its-pointless.github.io/files/24  termux extras

Then run the following commands:

# Install GnuPG.
apt install gnupg
# Download GPG signature file.
curl -O https://its-pointless.github.io/setup-pointless-repo.sh
# add the key to apt
apt-key add pointless.gpg
# Update the package list.
apt update
# Install ECL.
apt install ecl

Setup Emacs

Till now, the ECL should be usable already. But without SLIME/SLY, what is the difference between using ECL in Termux and using CL REPL?

First you have to install Emacs on Termux.

~ $ apt install emacs

Then it is needed to setup the Emacs for connecting the ECL. It would be a good idea to use Git to manage your Emacs configurations, like what I did. Simply copy the configuration files and put them to the corresponding places.

One setting that might need to be changed is the variable inferior-lisp-program. You need to change it as the following.

(setq inferior-lisp-program "ecl")

Run It!

It is the moment now. First take a deep breath and calm down.

Boot the Emacs, run command slime and you will see it compiling packages. It would take some time so you can make yourself a cookie now. Hope you did not finish your coffee ;-)

After it finishes, you are able to use the REPL inside our favorite Emacs. Try evaluate

(format t "Hello, world")

and see the result.


comments powered by Disqus