0

I have the following code in a buffer (file ~/firsts.lsp):

(defun firsts (l)
  (cond
    ((null l) ())
    (T (cons (car (car l)) (firsts (cdr l))))))

(firsts '((A B) (C D) (E F)))

I would like to "run" this script and see the following output (or a reasonable variant thereof):

(A C E)

My buffer shows this mode:

(Lisp [COMMON-LISP-USER cmucl] adoc)

In trying to run it, I tried C-c C-k, which created a buffer slime-compilation that showed the file was "compiled" without errors, but I do not see a way to get the compiled code to execute or run the entire script through the interpreter.

Slime is installed and running (it's what coordinates the compilation). I know that I can run the forms through the repl, in a form by form manner, but I would like to run the entire script interactively.

Software Environment: Mac OS X 10.12.3 GNU Emacs 25.1.1 Slime ChangeLog dates 2016-04-19 CMU Common Lisp 21b (21B Unicode) but same result with SBCL 1.3.14

4
  • common-lisp.net/project/slime/doc/html/… Commented Feb 6, 2017 at 4:16
  • @jenesaisquoi C-c C-b is bound to slime-interrupt. The slime manual doesn't mention slime-eval-buffer (although the command works using M-x slime-eval-buffer, there doesn't appear to be a key binding). Commented Feb 6, 2017 at 4:33
  • @RainerJoswig the link is to the slime documentation, but does not include the seemingly correct slime-eval-buffer, none of the commands in the doc are what I was asking about. The closest being slime-eval-region but that's not ideal. Commented Feb 6, 2017 at 4:37
  • 1
    @decuser: if you want to see output, then you need to output something. See the various print routines in Common Lisp. Then you can see in the slime manual how to load something, which then also will execute the code which outputs something. Commented Feb 6, 2017 at 4:48

1 Answer 1

3

One can imagine various ways how a Lisp source editor and a Listener (a read-eval-print-loop) work together. While SLIME is generally quite good, some of the interaction is slightly clumsy.

In this case there I use three ways to evaluate a buffer with SLIME/Emacs:

  • select the region, then evaluate the region using SLIME
  • SLIME eval buffer
  • save buffer, load buffer or compile-and-load buffer using SLIME

Note that if you evaluate things, results are printed in the mini buffer.

You also want to actually print something, so that you can see what happens.

Compiling things before loading/executing can help find errors. I use that often.

The actual list of key-commands for a buffer is seen on control-h m.

Side notes about interaction when evaluating a buffer

Another interaction style would be to feed each expression to a listener/repl buffer, have the results print there, until an error happens or there are no more expressions. But I don't think SLIME supports that in a direct way.

The LispWorks IDE lets you evaluate a buffer and the output (incl. the evaluation results) is displayed in a corresponding output pane.

The Clozure CL IDE lets you evaluate a buffer and the expressions are evaluated in the top most listener. Printed is the output and the last result.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.