Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a command to halt the interpreter in Common Lisp?

I'm looking for an expression that will cause the interpreter to exit when it is evaluated.

I've found lots of implementation-specific ones but none in the HyperSpec, and I was wondering if there were any that I wasn't seeing defined in the specification. I've found that (quit) is recognized by both CLISP and SLIME, and (exit) is recognized only by CLISP, but I can't find any documentation that references either of these.

like image 962
Haldean Brown Avatar asked Dec 13 '10 02:12

Haldean Brown


People also ask

Which command is used to exit Lisp system?

You can quit your lisp session by getting to the command line (possibly through pressing Control-C), then typing (quit) and pressing return.

What is a Lisp statement?

Lisp is an expression oriented language. Unlike most other languages, no distinction is made between "expressions" and "statements"; all code and data are written as expressions.

How do I run a Lisp program?

Example: Step 1: After logging into a CUIT machine, enter "lisp" after the $ shell prompt and then hit <return>. Another way is to run lisp via emacs: Meta-x run-lisp (i.e. hit 'esc' followed by 'x', type "run-lisp" and you'll be in lisp mode from which you can load files of lisp code...)


5 Answers

Since most Lisps import a quit function into CL-USER, CL-USER::QUIT is a good guess without knowing the implementation specific package where it is.

(cl-user::quit)

Note the two colons, since QUIT does not need to be exported from the CL-USER package.

like image 71
Rainer Joswig Avatar answered Oct 03 '22 11:10

Rainer Joswig


As far as I know, this is not covered by the Spec, and you will have to use the implementation-specific solutions, or maybe try and look if someone has already written a trivial-quit lib (or start one on CLiki).

If you only care about interactive use, ,q in SLIME will always do the right thing. Otherwise, you may use read-time conditionals like this:

(defun my-quit ()
  #+sbcl (sb-ext:quit)
  #+clisp (ext:exit)
  #+ccl (ccl:quit)
  #+allegro (excl:exit)) ;; and so on ...

#+ checks, if the following symbol is in *features*. If not, the following form will be treated as white-space. (There is also #- for the opposite).

like image 29
danlei Avatar answered Oct 02 '22 11:10

danlei


There is no standard way to exit a CL environment. To find out how to do it in the implementation you're using, read its documentation.

In sbcl, (sb-ext:quit) will do the trick. For clisp, it's (ext:exit). The clisp documentation for the command is at http://clisp.sourceforge.net/impnotes.html#quit

like image 24
Xach Avatar answered Sep 30 '22 11:09

Xach


There is an ASDF library called shut-it-down that provides a quit function that works by just having cases for the common CL implementations.

like image 34
Haldean Brown Avatar answered Oct 02 '22 11:10

Haldean Brown


You can use (uiop:quit). This is included in most lisps.

like image 39
Andrew Young Avatar answered Oct 04 '22 11:10

Andrew Young