[slime-devel] Not exactly 'presentation types for emacs' but useful anyway

Antonio Menezes Leitao aml at gia.ist.utl.pt
Tue May 17 12:34:44 UTC 2005


Hi,

I made a quick hack that allows the Slime listener to use Lisp objects
that were returned from the Common Lisp environment.  We already can
do this using *, **, and *** variables but, to me, is not enough.  I
have an hard time remembering the number of stars that I should write
and, moreover, I prefer to 'point' to a value that is presented in the
listener and I use it in the construction of next expression, just
like in Symbolics Lisp machines.  For those who never saw the
Symbolics environment, let me give you a description of what I can do
with this patch to Slime:

CL-USER> (cons 1 2)
(1 . 2)  ;;this is just like in good old Slime
CL-USER> (cons (1 . 2) (1 . 2))  ;; something new: I wrote "(cons "
;;and then I moved the cursor to the previous line and pressed return.
;;The previous output is copied to the current prompt but, in fact, it's
;;not only text.  It also represents the previous value returned by the
;;environment.  In this example I did the same operation twice and
then I wrote the closing ")". The result, as expected, is:
((1 . 2) 1 . 2)
CL-USER> (eq (car ((1 . 2) 1 . 2)) (cdr ((1 . 2) 1 . 2))) ;;again, I
wrote "(eq (car " and then I copied the previous output (using
return).  Then, I wrote ") (cdr " and I copied again the previous
output.  After finishing the form (with "))"), the environment returns:
T ;;as expected.

You cannot see it in this email (I presume) but I also mark the reused
values in a different color and I make then read-only (in Emacs) so
that you can see that they are a different beast.

Another interesting extension is to directly inspect any returned
value.  I changed the inspect command so that, whenever the cursor is
over a returned value, C-cC-I automatically inspects it.

There are lots of other things that we can do like discovering the
types of the presented values and restrict their use for certain
operations.  For example, if there's a function that asks the user for
a number, we can allow him to reuse old values as long as they are of
type number.  In short, this is just a quick hack to provide a
stripped down version of presentation types that works with emacs.  I
guess that the edit-value feature of Slime could also be rewritten to
take advantage of this stuff.

Now, it should be obvious that I am keeping all the returned values in
the Common Lisp side for further use.  This means that they are not
GCed.  So, from time to time, it might be wise to clean the Listener
(just like before, with C-cC-t) or just the previous output (with
C-cC-o).  This also releases the corresponding objects from the Common
Lisp side.

I suggest you try it out.

If the Slime team thinks this is useful then I suggest that you take a
good look at the code (as you usually do :-) and refactor it radically
because I did a lot of copy&paste just to test the idea.  And it might
also contains lots of bugs :-)

There are also lots of improvements that can be done like not storing
the values that don't require identity preservation (like small
numbers, and characters), like providing the functions that allow the
type of a value to be returned (e.g., to provide a menu of operations
for the object, etc), like allowing parts of lists to be reuse (this
one seems easy but requires different conventions for the gestures
needed for reusing previous values), etc, etc.

Best regards,

António Leitão.

Here's the patch:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 11860 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/slime-devel/attachments/20050517/01b18ea6/attachment.obj>


More information about the slime-devel mailing list