Cyrus Harmon | 27 Jan 22:41 2011

named-readtables/SLIME interaction problem


I ran into a problem with SLIME where I was getting errors the second time I would compile a buffer with
contents such as the following:

(cl:eval-when (:compile-toplevel :load-toplevel :execute)
 (ql:quickload 'named-readtables))

(defpackage #:reader-macro-test
  (:use #:cl))

(in-package #:reader-macro-test)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (named-readtables:defreadtable readtable-test
    (:merge :standard)))

(named-readtables:in-readtable readtable-test)

It turns out that the problem has to do with the way SLIME deals with the style-warning that the defreadtable
gives about overwriting the existing readtable. The defreadtable form clears out the bindings for the
existing reader, then issues the warning. SLIME parses the buffer and picks up that we're in the
#:reader-macro-test package and sets *readtable* to be the readtable that we've just clobbered and then
in SLIMEs error/warning handling code it further frobs (a copy of) the (now empty-ish) readtable and then
attempts to read using that readtable and fails.

Tobias rightly points out that SLIME should have better support for named-readtables. It also seems to me
that SLIME might want to make greater assurances about the state of the reader in its error handling code.

But the simple, expedient fix is:

--- named-readtables.lisp	2011-01-27 09:14:38.000000000 -0800
+++
/Users/sly/quicklisp/dists/quicklisp/software/named-readtables-20101006-darcs/named-readtables.lisp	2011-01-27
13:36:53.000000000 -0800
 <at>  <at>  -132,9 +132,9  <at>  <at> 
               (cond ((not readtable)
                      (setq readtable (make-readtable ',name)))
                     (t
-                     (setq readtable (%clear-readtable readtable))
                      (simple-style-warn "Overwriting already existing readtable ~S."
-                                        readtable)))
+                                        readtable)
+                     (setq readtable (%clear-readtable readtable))))
               , <at> (loop for option in merge-clauses
                       collect (process-option option 'readtable))
               , <at> (loop for option in case-clauses

Explicit SLIME support for named-readtables would be great, but, in the meantime, it would be nice to see
this in the named-readtables source.

Thanks,

Cyrus

Gmane