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

5

23

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.

Actionable answered 13/12, 2010 at 2:35 Comment(1)
It is implementation specific if there is an interpreter and if Lisp code runs interpreted. Most Common Lisp implementations provide a compiler. In implementations like SBCL there is only a compiler and no interpreter. CCL compiles everything by default. It is like asking how to shut down the Diesel engine of cars, when there are most cars having not a Diesel engine.Trainer
A
1

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.

Actionable answered 11/6, 2019 at 17:41 Comment(0)
T
25

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.

Trainer answered 13/12, 2010 at 8:12 Comment(0)
B
20

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).

Batrachian answered 13/12, 2010 at 3:48 Comment(5)
Here's a google code search that points to what SLIME uses in each of these cases: google.com/codesearch?q=%22defimplementation+quit-lisp%22Bastardize
Awesome. Any idea if there's a catch-all I can use, like "if none of these features are found, try running (exit)"?Actionable
haldean: Not sure what you mean. You can try running anything you want. :-) Since it's not standardized, and they don't seem to be at all consistent, I don't know how you'd decide what to pick. Most trivial-* libraries, IIRC, signal an error if you're using an unknown compiler.Bastardize
haldean, probably a bit late, but you can do: #-(or sbcl clisp ccl ...) (exit) at the bottom of all your #+ formsCask
FWIW, in case one wishes to exit with a particular exit code using SBCL, one can instead do, e.g., (sb-ext:exit :code 1) -- that will exit with exit code 1. See sbcl.org/manual/#Exit for more detail. (I know this is only an SBCL case, and not a direct answer to the question, but it's what I was looking for when I found this question and answer, so adding it as a comment.)Bonhomie
C
7

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

Cognizable answered 13/12, 2010 at 4:1 Comment(0)
O
4

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

Orthochromatic answered 20/3, 2020 at 11:2 Comment(0)
A
1

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.

Actionable answered 11/6, 2019 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.