Preliminary DOCUMENTATION, APROPOS and friends.
[jscl.git] / src / documentation.lisp
1 ;;; documentation.lisp --- Accessing DOCUMENTATION
2
3 ;;; APROPOS and friends
4
5 (defun map-apropos-symbols (function string package)
6   (flet ((handle-symbol (symbol)
7            ;; TODO: it's implementation-dependent, though CHAR-EQUAL seems
8            ;; more reasonable nevertheless
9            (when (search string (symbol-name symbol) :test #'char=)
10              (funcall function symbol))))
11     (if package
12         (do-symbols (symbol package) (handle-symbol symbol))
13         (do-all-symbols (symbol) (handle-symbol symbol)))))
14
15 (defun apropos-list (string &optional package)
16   (let (symbols)
17     (map-apropos-symbols
18      (lambda (symbol)
19        (pushnew symbol symbols :test #'eq))
20      string package)
21     symbols))
22
23 (defun apropos (string &optional package)
24   (map-apropos-symbols
25    (lambda (symbol)
26      (format t "~S" symbol)
27      (when (boundp symbol)
28        (format t " (bound)"))
29      (when (fboundp symbol)
30        (format t " (fbound)"))
31      (terpri))
32    string package))
33
34 ;;; DESCRIBE
35
36 ;; TODO: this needs DESCRIBE-OBJECT as generic method
37 ;; TODO: indentation for nested paragraphs
38 (defun describe (object &optional stream)
39   (declare (ignore stream))
40   (typecase object
41     (cons
42      (format t "~S~%  [cons]~%" object))
43     (integer
44      (format t "~S~%  [integer]~%" object))
45     (symbol
46      (format t "~S~%  [symbol]~%" object)
47      (when (boundp object)
48        (format t "~%~A names a special variable:~%  Value: ~A~%"
49                object (symbol-value object))
50        (let ((documentation (documentation object 'variable)))
51          (when documentation
52            (format t "  Documentation:~%~A~%" documentation))))
53      (when (fboundp object)
54        (format t "~%~A names a function:~%" object)
55        (let ((documentation (documentation object 'function)))
56          (when documentation
57            (format t "  Documentation:~%~A~%" documentation)))))
58     (string
59      (format t "~S~%  [string]~%~%Length: ~D~%"
60              object (length object)))
61     (float
62      (format t "~S~%  [float]~%" object))
63     (array
64      (format t "~S~%  [array]~%" object))
65     (function
66      (format t "~S~%  [function]~%" object)
67      (let ((documentation (documentation object 'function)))
68        (when documentation
69          (format t "  Documentation:~%~A~%" documentation))))
70     (T
71      (warn "~A not implemented yet for ~A" 'describe object)))
72   (values))