1 ;;;; implementation of CL:DOCUMENTATION
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is in the public domain and is provided with absolutely no
7 ;;;; warranty. See the COPYING and CREDITS files for more information.
12 (if (typep x 'generic-function)
13 (slot-value x '%documentation)
16 (defun (setf fun-doc) (new-value x)
17 (if (typep x 'generic-function)
18 (setf (slot-value x '%documentation) new-value)
19 (setf (%fun-doc x) new-value)))
21 ;;; functions, macros, and special forms
22 (defmethod documentation ((x function) (doc-type (eql 't)))
25 (defmethod documentation ((x function) (doc-type (eql 'function)))
28 (defmethod documentation ((x list) (doc-type (eql 'compiler-macro)))
29 (awhen (compiler-macro-function x)
30 (documentation it t)))
32 (defmethod documentation ((x list) (doc-type (eql 'function)))
33 (when (legal-fun-name-p x)
34 (or (random-documentation x 'function)
36 (fun-doc (fdefinition x))))))
38 (defmethod documentation ((x symbol) (doc-type (eql 'function)))
39 (when (legal-fun-name-p x)
40 (or (random-documentation x 'function)
41 ;; Nothing under the name, check the function object.
43 (fun-doc (if (special-operator-p x)
45 (or (macro-function x)
46 (fdefinition x))))))))
48 (defmethod documentation ((x symbol) (doc-type (eql 'compiler-macro)))
49 (awhen (compiler-macro-function x)
50 (documentation it t)))
52 (defmethod documentation ((x symbol) (doc-type (eql 'setf)))
53 (fdocumentation x 'setf))
55 (defmethod documentation ((x symbol) (doc-type (eql 'optimize)))
56 (random-documentation x 'optimize))
58 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 't)))
59 (setf (fun-doc x) new-value))
61 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 'function)))
62 (setf (fun-doc x) new-value))
64 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
65 (when (legal-fun-name-p x)
66 (setf (random-documentation x 'function) new-value)))
68 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'compiler-macro)))
69 (awhen (compiler-macro-function x)
70 (setf (documentation it t) new-value)))
72 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'function)))
73 (when (legal-fun-name-p x)
74 (setf (random-documentation x 'function) new-value)))
76 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'compiler-macro)))
77 (awhen (compiler-macro-function x)
78 (setf (documentation it t) new-value)))
80 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'setf)))
81 (setf (fdocumentation x 'setf) new-value))
83 ;;; method combinations
84 (defmethod documentation ((x method-combination) (doc-type (eql 't)))
85 (slot-value x '%documentation))
87 (defmethod documentation
88 ((x method-combination) (doc-type (eql 'method-combination)))
89 (slot-value x '%documentation))
91 (defmethod documentation ((x symbol) (doc-type (eql 'method-combination)))
92 (random-documentation x 'method-combination))
94 (defmethod (setf documentation)
95 (new-value (x method-combination) (doc-type (eql 't)))
96 (setf (slot-value x '%documentation) new-value))
98 (defmethod (setf documentation)
99 (new-value (x method-combination) (doc-type (eql 'method-combination)))
100 (setf (slot-value x '%documentation) new-value))
102 (defmethod (setf documentation)
103 (new-value (x symbol) (doc-type (eql 'method-combination)))
104 (setf (random-documentation x 'method-combination) new-value))
107 (defmethod documentation ((x standard-method) (doc-type (eql 't)))
108 (slot-value x '%documentation))
110 (defmethod (setf documentation)
111 (new-value (x standard-method) (doc-type (eql 't)))
112 (setf (slot-value x '%documentation) new-value))
116 ;;; KLUDGE: It's nasty having things like this accessor
117 ;;; (PACKAGE-DOC-STRING) floating around out in this mostly-unrelated
118 ;;; source file. Perhaps it would be better to support WARM-INIT-FORMS
119 ;;; by analogy with the existing !COLD-INIT-FORMS and have them be
120 ;;; EVAL'ed after basic warm load is done? That way things like this
121 ;;; could be defined alongside the other code which does low-level
122 ;;; hacking of packages.. -- WHN 19991203
124 (defmethod documentation ((x package) (doc-type (eql 't)))
125 (package-doc-string x))
127 (defmethod (setf documentation) (new-value (x package) (doc-type (eql 't)))
128 (setf (package-doc-string x) new-value))
130 ;;; types, classes, and structure names
131 (defmethod documentation ((x structure-class) (doc-type (eql 't)))
132 (fdocumentation (class-name x) 'type))
134 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
135 (fdocumentation (class-name x) 'type))
137 (defmethod documentation ((x standard-class) (doc-type (eql 't)))
138 (slot-value x '%documentation))
140 (defmethod documentation ((x standard-class) (doc-type (eql 'type)))
141 (slot-value x '%documentation))
143 ;;; although the CLHS doesn't mention this, it is reasonable to assume
144 ;;; that parallel treatment of condition-class was intended (if
145 ;;; condition-class is in fact not implemented as a standard-class or
146 ;;; structure-class).
147 (defmethod documentation ((x condition-class) (doc-type (eql 't)))
148 (fdocumentation (class-name x) 'type))
150 (defmethod documentation ((x condition-class) (doc-type (eql 'type)))
151 (fdocumentation (class-name x) 'type))
153 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
154 (or (fdocumentation x 'type)
155 (let ((class (find-class x nil)))
157 (slot-value class '%documentation)))))
159 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
160 (fdocumentation x 'structure))
162 (defmethod (setf documentation) (new-value
165 (setf (fdocumentation (class-name x) 'type) new-value))
167 (defmethod (setf documentation) (new-value
169 (doc-type (eql 'type)))
170 (setf (fdocumentation (class-name x) 'type) new-value))
172 (defmethod (setf documentation) (new-value
175 (setf (slot-value x '%documentation) new-value))
177 (defmethod (setf documentation) (new-value
179 (doc-type (eql 'type)))
180 (setf (slot-value x '%documentation) new-value))
182 (defmethod (setf documentation) (new-value
185 (setf (fdocumentation (class-name x) 'type) new-value))
187 (defmethod (setf documentation) (new-value
189 (doc-type (eql 'type)))
190 (setf (fdocumentation (class-name x) 'type) new-value))
192 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
193 (if (or (structure-type-p x) (condition-type-p x))
194 (setf (fdocumentation x 'type) new-value)
195 (let ((class (find-class x nil)))
197 (setf (slot-value class '%documentation) new-value)
198 (setf (fdocumentation x 'type) new-value)))))
200 (defmethod (setf documentation) (new-value
202 (doc-type (eql 'structure)))
203 (setf (fdocumentation x 'structure) new-value))
206 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
207 (fdocumentation x 'variable))
209 (defmethod (setf documentation) (new-value
211 (doc-type (eql 'variable)))
212 (setf (fdocumentation x 'variable) new-value))
214 ;;; default if DOC-TYPE doesn't match one of the specified types
215 (defmethod documentation (object doc-type)
216 (warn "unsupported DOCUMENTATION: type ~S for object of type ~S"
221 ;;; default if DOC-TYPE doesn't match one of the specified types
222 (defmethod (setf documentation) (new-value object doc-type)
223 ;; CMU CL made this an error, but since ANSI says that even for supported
224 ;; doc types an implementation is permitted to discard docs at any time
225 ;; for any reason, this feels to me more like a warning. -- WHN 19991214
226 (warn "discarding unsupported DOCUMENTATION of type ~S for object ~S"
231 ;;; extra-standard methods, for getting at slot documentation
232 (defmethod documentation ((slotd standard-slot-definition) (doc-type (eql 't)))
233 (declare (ignore doc-type))
234 (slot-value slotd '%documentation))
236 (defmethod (setf documentation)
237 (new-value (slotd standard-slot-definition) (doc-type (eql 't)))
238 (declare (ignore doc-type))
239 (setf (slot-value slotd '%documentation) new-value))
241 ;;; Now that we have created the machinery for setting documentation, we can
242 ;;; set the documentation for the machinery for setting documentation.
244 (setf (documentation 'documentation 'function)
245 "Return the documentation string of Doc-Type for X, or NIL if none
246 exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE, SETF, and T.
248 Function documentation is stored separately for function names and objects:
249 DEFUN, LAMBDA, &co create function objects with the specified documentation
252 \(SETF (DOCUMENTATION NAME 'FUNCTION) STRING)
254 sets the documentation string stored under the specified name, and
256 \(SETF (DOCUMENTATION FUNC T) STRING)
258 sets the documentation string stored in the function object.
260 \(DOCUMENTATION NAME 'FUNCTION)
262 returns the documentation stored under the function name if any, and
263 falls back on the documentation in the function object if necessary.")