common-lisp Working with SLIME Using REPL


Example

CL-USER> (+ 2 3)
5
CL-USER> (sin 1.5)
0.997495
CL-USER> (mapcar (lambda (x) (+ x 2)) '(1 2 3))
(3 4 5)

The result that is printed after evaluation is not only a string: there is full-on Lisp object behind it which can be inspected by right-clicking on it and choosing Inspect.

Multi-line input is also possible: use C-j to put new line. Enter-key will cause the entered form to be evaluated and if the form is not finished, will likely cause an error:

CL-USER> (mapcar (lambda (x y)
                   (declare (ignore y))
                   (* x 2))
                 '(1 2 3)
                 '(:a :b :c))
(2 4 6)

Error handling

If evaluation causes an error:

CL-USER> (/ 3 0)

This will pop up a debugger buffer with the following content (in SBCL lisp):

arithmetic error DIVISION-BY-ZERO signalled
Operation was /, operands (3 0).
   [Condition of type DIVISION-BY-ZERO]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1004FA8033}>)

Backtrace:
  0: (SB-KERNEL::INTEGER-/-INTEGER 3 0)
  1: (/ 3 0)
  2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (/ 3 0) #<NULL-LEXENV>)
  3: (EVAL (/ 3 0))
  4: (SWANK::EVAL-REGION "(/ 3 0) ..)
  5: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
--- more ---

Moving cursor down passed --- more --- will cause the backtrace to expand further.

At each line of the backtrace pressing Enter will show more information about a particular call (if available).

Pressing Enter on the line of restarts will cause a particular restart to be invoked. Alternatively, the restart can be chosen by number 0, 1 or 2 (press corresponding key anywhere in the buffer). The default restart is marked by a star and can be invoked by pressing key q (for "quit"). Pressing q will close the debugger and show the following in REPL

; Evaluation aborted on #<DIVISION-BY-ZERO {10064CCE43}>.
CL-USER> 

Finally, quite rarely, but Lisp might encounter an error that cannot be handled by Lisp debugger, in which case it will drop into low-level debugger or finish abnormally. To see the cause of this kind of error, switch to *inferior-lisp* buffer.