Subject: Re: How to programmatically exit?
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 25 Oct 2008 20:09:13 -0500
Newsgroups: comp.lang.lisp
Message-ID: <IoKdnUnxRvOkXp7UnZ2dnUVZ_tjinZ2d@speakeasy.net>
Waldek Hebisch  <hebisch@math.uni.wroc.pl> wrote:
+---------------
| Russell Wallace <russell.wallace@gmail.com> wrote:
| > From within a portable Lisp program, how do you exit cleanly...
| > exit(0) in C? I can't find anything in the hyperspec or Google...
| > maybe I'm overlooking something obvious.
| 
| Such functionality is missing from ANSI CL, so any solution will
| be more or less unportable.  The following is a reasonable
| approximation for free Lisp implementations...
...
| ;;; How to exit Lisp process
| #+:gcl
| (defun quit() (lisp::quit))
| 
| #+:sbcl
| (defun quit()
|     (sb-ext::quit))
+---------------

And so on...

A style that's less visually confusing (IMHO) puts all of the
feature tests[1] inside a single copy of the function in question,
documenting the common API in a single place. The following is
a merge of the set from <http://www.cliki.net/CLOCC-PORT>, the
set from Maxima, and yours:

    (defun quit (&optional code)
      ;; This group from "clocc-port/ext.lisp"
      #+allegro (excl:exit code)
      #+clisp (#+lisp=cl ext:quit #-lisp=cl lisp:quit code)
      #+cmu (ext:quit code)
      #+cormanlisp (win32:exitprocess code)
      #+gcl (lisp:bye code)			; XXX Or is it LISP::QUIT?
      #+lispworks (lw:quit :status code)
      #+lucid (lcl:quit code)
      #+sbcl (sb-ext:quit
	      :unix-code (typecase code (number code) (null 0) (t 1)))
      ;; This group from Maxima
      #+kcl (lisp::bye)				; XXX Does this take an arg?
      #+scl (ext:quit code)			; XXX Pretty sure this *does*.
      #+(or openmcl mcl) (ccl::quit)
      #+abcl (cl-user::quit)
      #+ecl (si:quit)
      ;; This group from <hebisch@math.uni.wroc.pl>
      #+poplog (poplog::bye)			; XXX Does this take an arg?
      #-(or allegro clisp cmu cormanlisp gcl lispworks lucid sbcl
	    kcl scl openmcl mcl abcl ecl)
      (error 'not-implemented :proc (list 'quit code)))


-Rob

p.s. Note that you never need an explicit keyword package marker on
a symbol in a feature test, e.g. #+:FOO, since feature expressions
are read *in* the KEYWORD package, see CLHS "2.4.8.17 Sharpsign Plus",
"2.4.8.18 Sharpsign Minus", & "24.1.2.1 Feature Expressions".

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607