Subject: Re: How to programmatically exit?
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 28 Oct 2008 05:47:57 -0500
Newsgroups: comp.lang.lisp
Message-ID: <RaadnbmwuIJAcJvUnZ2dnUVZ_hydnZ2d@speakeasy.net>
Willem Broekema  <metawilm@gmail.com> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) wrote:
| >  (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)
| >     ...
| >     #-(or allegro clisp cmu cormanlisp gcl lispworks lucid sbcl
| >        kcl scl openmcl mcl abcl ecl)
| >     (error 'not-implemented :proc (list 'quit code)))
| 
| You could even skip the #-(...) in this case. :)
+---------------

Yes, that's true. But exiting the entire program is a very special
case and I didn't want to encourage sloppiness in the general case
where you *do* want to return a value, e.g., this function from the
"archive_0.7.0" package:

    ;;; stat field accessors
    (defun stat-mode (stat)
      #+sbcl (sb-posix::stat-mode stat)
      #+lispworks (file-stat-mode stat)
      #+clisp (posix:convert-mode (posix:file-stat-mode state))
      #+cmucl (mode stat)
      #-(or sbcl lispworks clisp cmucl) (error "Not implemented"))

So it's probably best to always include the #-(OR ...) list,
just to avoid mistakes by accident.

Although, now that you mention it, there *is* one other special case
that I can think of where the #-(OR ...) is unnecessary and, in fact,
unwanted, and that's where you're going to return a default value if
the implementation-specific value is NIL, e.g.:

    ;;; This version morphed very slightly from
    ;;; <http://cl-cookbook.sourceforge.net/os.html>
    (defun getenv (name &optional default)
      (or
       #+cmu (cdr (assoc name ext:*environment-list* :test #'string=))
       #+allegro (sys:getenv name)
       #+clisp (ext:getenv name)
       #+ecl (si:getenv name)
       #+sbcl (sb-unix::posix-getenv name)
       #+lispworks (lispworks:environment-variable name)
       default))


-Rob

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