Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a reference to the last returned object in Emacs Slime

Using Emacs Slime, how can I access the object or value that was returned by the last expression in the REPL?

In ipython it's _ so that I can save it in a variable if the return value is what I expected.

Is there something similar for Slime?

like image 482
Suzana Avatar asked Jan 04 '16 16:01

Suzana


2 Answers

Common Lisp defines some variables which are bound the previous form and their values. These are:

  • *, **, *** The most recent primary values.
  • /, //, /// The most recent values (each of these is a list).
  • +, ++, +++ The most recent forms.

These variables are bound each time a form is evaluated in the REPL (which is what Slime is doing). *, /, and + are bound the previous primary value, values and form. **, //, and ++ are bound to the previous values of *, /, //. ***, ///, and +++ are bound the previous values of **, //, ++.

Functions in Lisp may return more than one value; thus the difference between * which holds the primary (first) value and / which holds a list of all values.

like image 115
verdammelt Avatar answered Oct 01 '22 15:10

verdammelt


In addition to verdammelts answer, you can also copy and paste objects from the repl. For an example see the third image in this article (that I wrote). For more information you should look at the presentations section of the Slime manual.

like image 33
malisper Avatar answered Oct 01 '22 13:10

malisper