(in-package "SB-IMPL") ;(SB-IMPL, not SB!IMPL, since we're built in warm load.)
\f
-(defvar *describe-indentation-step* 3
- #+sb-doc
- "the number of spaces that sets off each line of a recursive description")
-
(declaim (ftype (function (t stream)) describe-object))
-(defgeneric describe-object ((x t) stream))
+(defgeneric describe-object (x stream))
(defun describe (x &optional (stream-designator *standard-output*))
#+sb-doc
"Print a description of the object X."
(let ((stream (out-synonym-of stream-designator)))
+ (fresh-line stream)
(pprint-logical-block (stream nil)
- (fresh-line stream)
(describe-object x stream)
- (fresh-line stream)))
+ (pprint-newline :mandatory stream)))
(values))
\f
;;;; miscellaneous DESCRIBE-OBJECT methods
(defmethod describe-object ((x array) s)
(let ((rank (array-rank x)))
- (cond ((> rank 1)
- (format s "~S ~_is " x)
- (write-string (if (%array-displaced-p x) "a displaced" "an") s)
- (format s " array of rank ~S." rank)
- (format s "~@:_Its dimensions are ~S." (array-dimensions x)))
- (t
+ (cond ((= rank 1)
(format s
"~@:_~S is a ~:[~;displaced ~]vector of length ~S." x
(and (array-header-p x) (%array-displaced-p x)) (length x))
(when (array-has-fill-pointer-p x)
(format s "~@:_It has a fill pointer, currently ~S."
- (fill-pointer x))))))
+ (fill-pointer x))))
+ (t
+ (format s "~S ~_is " x)
+ (write-string (if (%array-displaced-p x) "a displaced" "an") s)
+ (format s " array of rank ~S." rank)
+ (format s "~@:_Its dimensions are ~S." (array-dimensions x)))))
(let ((array-element-type (array-element-type x)))
(unless (eq array-element-type t)
(format s
(:function (if name
(format s "Function: ~S" x)
(format s "~S is a function." x))))
- (format s "~@:_Its associated name (as in ~S) is ~S."
+ (format s "~@:_~@<Its associated name (as in ~S) is ~2I~_~S.~:>"
'function-lambda-expression
(%fun-name x))
(case (widetag-of x)
(defmethod describe-object ((x function) s)
(%describe-fun x s :function))
-(defgeneric describe-symbol-fdefinition (function stream &key (name nil) ))
+(defgeneric describe-symbol-fdefinition (function stream &key name))
(defmethod describe-symbol-fdefinition ((fun function) stream &key name)
(%describe-fun fun stream :function name))
(multiple-value-bind (symbol status)
(find-symbol (symbol-name x) package)
(declare (ignore symbol))
- (format s "~S is ~_an ~(~A~) symbol ~_in ~S."
+ (format s "~@<~S is ~_an ~(~A~) symbol ~_in ~S.~:>"
x status (symbol-package x)))
- (format s "~S is ~_an uninterned symbol." x)))
+ (format s "~@<~S is ~_an uninterned symbol.~:>" x)))
;; TO DO: We could grovel over all packages looking for and
;; reporting other phenomena, e.g. IMPORT and SHADOW, or
;; availability in some package even after (SYMBOL-PACKAGE X) has
(let* ((kind (info :variable :kind x))
(wot (ecase kind
(:special "special variable")
+ (:macro "symbol macro")
(:constant "constant")
(:global "undefined variable")
(:alien nil))))
(sb-alien::heap-alien-info-type info)))
(format s "~@<Its current value is ~3I~:_~S.~:>"
(eval x))))
+ ((eq kind :macro)
+ (let ((expansion (info :variable :macro-expansion x)))
+ (format s "~@:_It is a ~A with expansion ~S." wot expansion)))
((boundp x)
- (format s "~@:_It is a ~A; its ~_value is ~S." wot (symbol-value x)))
+ (format s "~@:_~@<It is a ~A; its ~_value is ~S.~:>"
+ wot (symbol-value x)))
((not (eq kind :global))
- (format s "~@:_It is a ~A; no current value." wot)))
+ (format s "~@:_~@<It is a ~A; no current value.~:>" wot)))
(when (eq (info :variable :where-from x) :declared)
- (format s "~@:_Its declared type ~_is ~S."
+ (format s "~@:_~@<Its declared type ~_is ~S.~:>"
(type-specifier (info :variable :type x))))
(%describe-doc x s 'variable kind))
((fboundp x)
(describe-symbol-fdefinition (fdefinition x) s :name x)))
- ;; FIXME: Print out other stuff from the INFO database:
- ;; * Does it name a type?
- ;; * Is it a structure accessor? (This is important since those are
- ;; magical in some ways, e.g. blasting the structure if you
- ;; redefine them.)
-
;; Print other documentation.
(%describe-doc x s 'structure "Structure")
(%describe-doc x s 'type "Type")
(%describe-doc x s 'setf "Setf macro")
-
(dolist (assoc (info :random-documentation :stuff x))
(format s
"~@:_Documentation on the ~(~A~):~@:_~A"
(car assoc)
(cdr assoc)))
- ;; Describe the associated class, if any.
+ ;; Mention the associated type information, if any.
+ ;;
+ ;; As of sbcl-0.7.2, (INFO :TYPE :KIND X) might be
+ ;; * :PRIMITIVE, which is handled by the FIND-CLASS case.
+ ;; * :DEFINED, which is handled specially.
+ ;; * :INSTANCE, which is handled by the FIND-CLASS case.
+ ;; * :FORTHCOMING-DEFCLASS-TYPE, which is an internal-to-the-compiler
+ ;; note that we don't try to report.
+ ;; * NIL, in which case there's nothing to see here, move along.
+ (when (eq (info :type :kind x) :defined)
+ (format s "~@:_It names a type specifier."))
(let ((symbol-named-class (cl:find-class x nil)))
(when symbol-named-class
- (format s "~&It names a class ~A." symbol-named-class)
- (describe symbol-named-class))))
+ (format s "~@:_It names a class ~A." symbol-named-class)
+ (describe symbol-named-class s))))