Providing better editing support for sbcl via readline

Posted by Steve on Mon 13 Apr 2009 at 11:45

The readline library is used by many programs which need to provide a pleasant environment for performing text entry, offering completion, history, and advanced editing facilities. There are applications which, for various reasons, do not use it, but this is something that may be fixed with the addition of the rlwrap readline wrapper.

Over the past few months I've been slowly getting to grips with coding in Lisp. The are several lisp environments availabe to users of Debian GNU/Linux and I have been alternating between two of them (clisp, & sbcl).

The first package, clisp, provides a nice environment with history, line editing and similar, by contrast the sbcl package has no history support, no editing support, and is less pleasant to use interactively. In short when I'm in the sbcl environment and I press "Up" to recall my previous line of entry I see nothing - which is often frustrating!

To solve this problem I installed the rlwrap package which wraps readline support around other programs:

skx@gold:~$ aptitude install rlwrap
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
  rlwrap
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 37.7kB of archives.
After this operation, 139kB of additional disk space will be used.
Get: 1 http://ftp.uk.debian.org sid/main rlwrap 0.28-2 [37.7kB]
Fetched 37.7kB in 0s (143kB/s)
Selecting previously deselected package rlwrap.
(Reading database ... 194601 files and directories currently installed.)
Unpacking rlwrap (from .../rlwrap_0.28-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up rlwrap (0.28-2) ...
skx@gold:~$

Once this is done I can invoke "rlwrap sbcl" to launch the sbcl environment with the readline wrapper around it. Suddenly the arrow keys work, I have persistant history, and command line editing works as it should.

It is hard to demonstrate this offline, but suffice it to say that I can run sbcl under rlwrap and I have persistant history - to the extent that I can load the environment and press "Up" a few times to repeat the things I entered last time round:

skx@gold:~$ rlwrap sbcl
This is SBCL 1.0.25.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at .

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (defvar test "Some text.  Mixed case")

TEST
* (string-downcase test)

"some text.  mixed case"
* (quit)
skx@gold:~$

While using rlwrap in this environment doesn't provide a great deal of difference it does make the work more pleasant, and I'm sure now I've experimented with it there will be more situations I'll use it.

rlwrap has several options which can be used to tweak the behaviour, the most useful of which I've found is the -c option (or "--complete-filenames") this allows the tool to keep track of the working directory and complete filenames appropriately, as you would see inside shells such as bash.

If you'd like to learn more about the provided options please see "man rlwrap", or view the file /usr/share/doc/rlwrap/README.

Share/Save/Bookmark


Posted by Anonymous (90.241.xx.xx) on Mon 13 Apr 2009 at 13:19
Erk, well rlwrap does indeed help a lot for quick jobs with programs that don't support readline. But if you want to use lisp environments, you _really_ want to be looking at slime. It's a lot more than just readline.

[ Parent | Reply to this comment ]

Posted by Steve (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Mon 13 Apr 2009 at 13:44
[ Send Message | View Steve's Scratchpad | View Weblogs ]

It seems that no matter which lisp environment I choose people tell me to use a different one! Still thanks for the recommendation, I will have a look at it and see how it differs.

Mostly my lisp usage is very basic and I'm not doing anything which is tied to a specific implementation. The only thing that seems a little fiddly and implementation-specific is the installation of non-(Debian)packaged libraries such as s-xml-rpc.

Using the lisp environment was just an obvious example for me, but I think that rlwrap might be new to others, and find a few good uses.

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (207.5.xx.xx) on Mon 13 Apr 2009 at 16:46
I suspect most serious sbcl users interact with it via emacs and slime.

[ Parent | Reply to this comment ]

Posted by Anonymous (93.35.xx.xx) on Thu 28 May 2009 at 07:35
Yep, Slime is the way to go: the sooner you start with it, the better.

[ Parent | Reply to this comment ]

Posted by Anonymous (85.1.xx.xx) on Sat 30 May 2009 at 09:19
This was an incredibly useful piece of advice! To slime or not to slime is not the question - it's useful in a number of places.

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search