1 ;;; $Id: utils.lisp,v 1.5 2003/02/06 23:25:52 kevin Exp $
3 ;;;; General purpose utilities
8 (defmacro aif (test then &optional else)
12 (defmacro awhen (test-form &body body)
16 (defun keyword-symbol? (x)
17 "Returns T if object is a symbol in the keyword package"
19 (string-equal "keyword" (package-name (symbol-package x)))))
21 (defun list-to-spaced-string (list)
23 (format nil "~A~{ ~A~}" (first list) (rest list))))
25 (defun indent-spaces (n &optional (stream *standard-output*))
26 "Indent n*2 spaces to output stream"
27 (let ((fmt (format nil "~~~DT" (+ n n))))
30 (defun print-file-contents (file &optional (strm *standard-output*))
31 "Opens a reads a file. Returns the contents as a single string"
32 (when (probe-file file)
33 (with-open-file (in file :direction :input)
34 (do ((line (read-line in nil 'eof)
35 (read-line in nil 'eof)))
37 (format strm "~A~%" line)))))
39 (defun date-string (ut)
40 (if (typep ut 'integer)
41 (multiple-value-bind (sec min hr day mon year dow daylight-p zone)
42 (decode-universal-time ut)
43 (declare (ignore daylight-p zone))
44 (format nil "~[Mon~;Tue~;Wed~;Thu~;Fri~;Sat~;Sun~], ~d ~[Jan~;Feb~;Mar~;Apr~;May~;Jun~;Jul~;Aug~;Sep~;Oct~;Nov~;Dec~] ~d ~2,'0d:~2,'0d:~2,'0d"
51 (defun lml-quit (&optional (code 0))
52 "Function to exit the Lisp implementation. Copied from CLOCC's QUIT function."
53 #+allegro (excl:exit code)
54 #+clisp (#+lisp=cl ext:quit #-lisp=cl lisp:quit code)
55 #+(or cmu scl) (ext:quit code)
56 #+cormanlisp (win32:exitprocess code)
58 #+lispworks (lw:quit :status code)
59 #+lucid (lcl:quit code)
60 #+sbcl (sb-ext:quit :unix-status (typecase code (number code) (null 0) (t 1)))
62 #-(or allegro clisp cmu scl cormanlisp gcl lispworks lucid sbcl mcl)
63 (error 'not-implemented :proc (list 'quit code)))
67 "Returns the current working directory. Based on CLOCC's DEFAULT-DIRECTORY function."
68 #+allegro (excl:current-directory)
69 #+clisp (#+lisp=cl ext:default-directory #-lisp=cl lisp:default-directory)
70 #+(or cmu scl) (ext:default-directory)
71 #+cormanlisp (ccl:get-current-directory)
72 #+lispworks (hcl:get-working-directory)
73 #+lucid (lcl:working-directory)
74 #+sbcl (sb-unix:posix-getcwd/)
75 #+mcl (ccl:mac-default-directory)
76 #-(or allegro clisp cmu scl sbcl cormanlisp lispworks lucid mcl) (truename "."))