source: trunk/j/src/org/armedbear/lisp/print-object.lisp @ 8609

Last change on this file since 8609 was 8609, checked in by piso, 16 years ago

Defined a PRINT-OBJECT method for structures.

File size: 3.2 KB
Line 
1;;; print-object.lisp
2;;;
3;;; Copyright (C) 2003-2005 Peter Graves
4;;; $Id: print-object.lisp,v 1.7 2005-02-20 14:11:53 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package #:system)
21
22(require 'clos)
23
24(when (autoloadp 'print-object)
25  (fmakunbound 'print-object))
26
27(defgeneric print-object (object stream))
28
29(defmethod print-object ((object t) stream)
30  (print-unreadable-object (object stream :type t :identity t)))
31
32(defmethod print-object ((object structure-object) stream)
33  (write-string (%write-to-string object) stream))
34
35(defmethod print-object ((object standard-object) stream)
36  (print-unreadable-object (object stream :identity t)
37    (format stream "~S" (class-name (class-of object))))
38  instance)
39
40(defmethod print-object ((class standard-class) stream)
41  (print-unreadable-object (class stream :identity t)
42    (format stream "~S ~S"
43            (class-name (class-of class))
44            (class-name class)))
45  class)
46
47(defmethod print-object ((gf standard-generic-function) stream)
48  (print-unreadable-object (gf stream :identity t)
49    (format stream "~S ~S"
50            (class-name (class-of gf))
51            (generic-function-name gf)))
52  gf)
53
54(defmethod print-object ((method standard-method) stream)
55  (print-unreadable-object (method stream :identity t)
56    (format stream "~S ~S~{ ~S~} ~S"
57            (class-name (class-of method))
58            (generic-function-name
59             (method-generic-function method))
60            (method-qualifiers method)
61            (mapcar #'class-name
62                    (method-specializers method))))
63  method)
64
65(defmethod print-object ((restart restart) stream)
66  (if *print-escape*
67      (print-unreadable-object (restart stream :type t :identity t)
68        (prin1 (restart-name restart) stream))
69      (restart-report restart stream)))
70
71(defmethod print-object ((c condition) stream)
72  (if *print-escape*
73      (call-next-method)
74      (let ((report (condition-report c)))
75        (cond ((stringp report)
76               (write-string report stream))
77              (t
78               (%format stream "~A" c))))))
79
80(defmethod print-object ((c simple-condition) stream)
81  (if *print-escape*
82      (call-next-method)
83      (let ((format-control (simple-condition-format-control c)))
84        (if format-control
85            (apply #'format stream format-control
86                   (simple-condition-format-arguments c))
87            (call-next-method)))))
88
89(defmethod print-object ((x undefined-function) stream)
90  (if *print-escape*
91      (call-next-method)
92      (format stream "The function ~S is undefined." (cell-error-name x))))
93
94(provide 'print-object)
Note: See TracBrowser for help on using the repository browser.