Monday, June 4

Save Slime And Die

The best way to work with a Lisp is to leave it running all the time and hack on it bit by bit, building up your program bit by bit, doing mini-tests and off-the-cuff code as you go along and shaping it..


Except if you are like me, you might be working on a laptop with a limited battery life and have a strict time limit to your lisp hacking. It's bothered me that when working with SLIME the only way to save a core was to start a lisp in a terminal, load up your systems and your files, then dump and use that with C-u M-x slime, which lets you enter a command line to start your lisp.


It annoys me because if you are like me, your code doesn't necessarily capture the actual state of your core: it also contains half a dozen test variables and functions that you entered in the repl and are useful to have hang around. So I tried to find a way to dump and restore core from within slime. I came up with the following function



(defun save-slime-and-die (core-file-name)
;; close all
(mapcar #'(lambda (x) (swank::close-connection x)) swank::*connections*)
#+sb-thread
(dolist (thread (remove (swank::current-thread) (swank::all-threads)))
(swank::kill-thread thread))
(sleep 1)
(save-lisp-and-die core-file-name))

It's obviously for sbcl, and the gotcha is that it has to be executed in the *inferior-lisp* buffer, but it works..C-u M-x sbcl --core test.core brings back core dumped with (save-slime-and-die #P"test.core")

5 comments:

Anonymous said...

Hi,

Obviously I'm a noob, but when I try (save-slime-and-die #P"test.core") it fails with the message:

invalid number of arguments: 1
[Condition of type SB-INT:SIMPLE-PROGRAM-ERROR]

I also see this:

; (SWANK::CLOSE-CONNECTION X)
;
; caught STYLE-WARNING:
; The function was called with one argument, but wants exactly three.

John Connors said...

It's been a long time since I posted this .. probably one of the functions that I called has changed it's parameter count in the meantime and needs an extra parameter..

Anonymous said...

Hi, useful tip to get around the "Cannot save core with multiple threads running" problem but can you point to where the #+ notation is explained. Thanks.

John Connors said...

Its a reader notation. I'd suggest reading (groan)
Maintaining Portable Lisp Programs to see how useful it is.

Spacebat said...

Make that (swank::close-connection x nil nil) and it works just fine.