Search code examples
emacslispcommon-lispslime

Evaluating in buffer different from evaluating in slime?


I am using emacs to learn how to program in common lisp, and I have bumped up against a confusing issue. When I enter the expression

(defconstant +some-constant+ (make-hash-table))

and I evaluate it with

M-x eval-buffer

I get the error

Symbol's function definition is void: defconstant

But if I copy and paste this into the slime repl, it works perfectly. Of course, this renders most of the handy keyboard shortcuts for evaluating lisp code within your program without having to execute the entire program. I end up copying everything out of my buffer into the slime terminal whenever I want to test something.

What is going on here?


Solution

  • M-x eval-buffer will evaluate the buffer as emacs lisp, not as Common Lisp. You probably want C-c C-k, which will compile and load the file.

    In general, if you see a lisp-related command without a prefix of slime- it is probably an emacs-lisp facility.