; -*- Package:SYSTEM-INTERNALS; Mode:LISP; Base:8 -*-
; MACHINE MISCELLANEOUS FUNCTIONS NOT WORTHY OF BEING IN QFCTNS
; ** (c) Copyright 1980 Massachusetts Institute of Technology **
"$Header: describe.l,v 1.3 85/03/24 11:23:34 sklower Exp $")
(setq SCCS-describe "@(#) describe.l 1.1 83/01/27 @(#)")
(environment-lmlisp (compile eval) (files struct flavorm))
(declare (special indent))
(defun describe (anything &optional no-complaints &aux (indent 0))
(describe-2 anything no-complaints))
(defun describe-2 (anything no-complaints &aux type)
(cond ((named-structure-p anything)
(describe-defstruct anything))
((and (instancep anything)
(get-handler-for anything ':describe))
(send anything ':describe))
((:typep anything 'flavor)
(describe-flavor anything))
(describe-array anything))
(describe-symbol anything))
(describe-list anything))
(describe-flonum anything))
(describe-bignum anything))
(format t "~%~vX~R is ~[even~;odd~]"
indent anything (if (evenp anything) 0 1)))
(format t "~%I don't know how to describe ~S" anything)))
(defun describe-1 (thing) ;an internal subroutine
(cond ((or (null thing) ;Don't recursively describe relatively boring things
(numberp thing) (symbolp thing) (stringp thing))
(t (let ((indent (+ indent 4)))
(defun describe-symbol (sym)
(let ((prinlevel 2) (prinlength 3))
(format t "~%~vXThe value of ~S is ~S" indent sym (symeval sym)))
(describe-1 (symeval sym))))
(let ((prinlevel 2) (prinlength 3))
(format t "~%~vX~S is the function ~S: ~S"
indent sym (getd sym) '(???)))
(describe-1 (getd sym))))
(do ((pl (plist sym) (cddr pl))
; (format t "~%~~vXS has property ~S: ~S" ; SMH@MIT-EMS
(format t "~%~vX~S has property ~S: ~S"
indent sym (car pl) (cadr pl))
(format t "~%~vX~S is a list" indent l))
;Fixed indent botch: this is not necessarily called from describe! SMH@EMS
(defun describe-defstruct
(x &optional defstruct-type
(indent (cond ((and (boundp 'indent) (fixp indent)) indent)
(setq description (get (or defstruct-type (named-structure-symbol x))
; (format t "~%~vX~S is a ~S~%" indent x (defstruct-description-name)) SMH@EMS
(format t "~%~vX~S is a ~S~%" indent x
(defstruct-description-name description))
(do l (defstruct-description-slot-alist) (cdr l) (null l)
(eval `(,(defstruct-slot-description-ref-macro-name (cdar l))
(defun describe-fclosure (cl)
(format t "~vX~%~S is an fclosure of ~S:~%" cl (fclosure-function cl))
(loop for pair in (fclosure-alist cl)
do (format t "~vX Value cell of ~S: ~32,7S~%"
(car pair) (cadr pair))))
(defun describe-flonum (x)
(format t "~%~vX~S is a flonum.~% " indent x)
;; (format T "Excess-2000 exponent ~O, 32-bit mantissa ~O~4,48O~4,48O (including sign)")
(defun describe-bignum (x)
(format t "~&~S is a bignum.~&It is ~R word~:P long."
(defun describe-array (array &aux arraydims ndims)
(format t "~vX~%This is a ~S type array."
indent (car (getaux array)))
(setq arraydims (cdr (arraydims array)))
(setq ndims (length arraydims))
(format t "~vX~%It is ~D-dimensional, with dimensions "
(do l arraydims (cdr l) (null l)
(format t "~s " (car l))))
(t (format t "~%It is ~S long." (car arraydims)))))
(t (ferror nil "~S is not an array" array))))
(defmacro mapatoms (fcnt) `(mapc ,fcnt (oblist)))
(declare (special apropos-substring return-list))
(defun apropos (apropos-substring &rest rest
(mapatoms #'apropos-1 pkg)
(defun apropos-1 (symbol)
(cond ((within-string apropos-substring (get_pname symbol))
(push symbol return-list)
(format t " - Function"))
(cond ((fboundp symbol) (princ ", Bound"))
(t (princ " - Bound")))))))
(defun within-string (s1 s2 &aux (len (flatc s1)))
(loop for i from 1 to (flatc s2)
with fc = (getcharn s1 1)
when (and (= (getcharn s2 i) fc)
(eqstr (substring s2 i len) s1))