home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / lisp / 2876 < prev    next >
Encoding:
Text File  |  1992-11-14  |  3.4 KB  |  87 lines

  1. Newsgroups: comp.lang.lisp
  2. Path: sparky!uunet!gumby!wupost!decwrl!ads.com!kerry
  3. From: kerry@ADS.COM (Kerry Koitzsch)
  4. Subject: Vendor independent analog to Symbolics GET-DEFSTRUCT-DESCRIPTION
  5. Message-ID: <1992Nov13.172451.16365@ads.com>
  6. Followup-To: Simon Clearys question
  7. Summary: Hard to do, make it part of Common Lisp
  8. Keywords: Vendor independent, dpANS
  9. Sender: usenet@ads.com (USENET News)
  10. Organization: Advanced Decision Systems, Mtn. View, CA (415) 960-7300
  11. Date: Fri, 13 Nov 1992 17:24:51 GMT
  12. Lines: 73
  13.  
  14. Hello LISP experts:
  15.  
  16.   Getting at the internal structure of defstructs in a portable way has
  17. always been a pain, given the lack of standardization of defstruct internal
  18. accessors in Common Lisp. Simon Clearys recent question about the analog
  19. to SI:GET-DEFSTRUCT-DESCRIPTION is a good example of this:
  20.  
  21. ;;; Vendor-indpendent analog of GET-DEFSTRUCT-DESCRIPTION for
  22. ;;; the 'Big Seven':
  23.  
  24. (defvar *vendor-defstruct-name-function*
  25. #+akcl #'(lambda(desc)(si::s-data-name desc))
  26. #+excl #'(lambda(desc)(slot-value desc 'excl::name))
  27. #+lucid #'(lambda(desc)(system::structure-ref desc 0 'lucid::defstruct))
  28. #+lispm #'(lambda(desc)(si:defstruct-description-name desc))
  29. #+:mcl #'(lambda(desc)(class-name (class-of desc)))
  30. #+cmu #'(lambda(desc)(kernel::structure-ref struct 0))
  31. #+xerox #'(lambda(desc)) ;;; ????
  32. "Given defstruct descriptor, return name.")
  33.  
  34. (defvar *vendor-defstruct-descriptor-function*
  35.   #+symbolics #'(lambda(name)(si:get name 'si:defstruct-description))
  36.   #+lucid #'(lambda(name)(gethash name lucid::*defstructs*))
  37.   #+excl #'(lambda(name)(get name 'excl::%structure-definition))
  38.   #+akcl #'(lambda (name)(get name 'si::s-data))
  39.   #+cmu #'(lambda (name)(ext:info c::type c::defined-structure-info name))
  40.   #+:mcl #'(lambda (name)(gethash name 'ccl::%defstructs%))
  41.   #+xerox #'(lambda(name)) ;;; ???
  42. "from symbol name of defstruct get the defstruct descriptor.")
  43.  
  44. (defun PSEUDO-QUOTE-READER (stream subchar arg)
  45.   "Reader to convert a function spec into a more parsable format."
  46.   (declare (ignore subchar arg))
  47.   (eval (list 'quote
  48.      (second (read-from-string 
  49.           (nsubstitute #\space #\#
  50.        (concatenate 'string "(" 
  51.         (read-line stream t nil t) ")")
  52.                    :test #'equal))))))
  53.  
  54. (defun PARSE-DEFSTRUCT-SPEC (struct)
  55. "Vendor independent way to get defstruct name from defstruct object."
  56. (let ((ans nil)
  57.       (*readtable* (copy-readtable)))
  58. (set-dispatch-macro-character #\# #\' (function pseudo-quote-reader))
  59. (set-dispatch-macro-character #\# #\< (function pseudo-quote-reader))
  60. (set-dispatch-macro-character #\# #\S (function pseudo-quote-reader))
  61. (setq ans (subseq (format nil "~a" struct) 3))
  62. (setq ans (subseq ans 0 (position #\space ans)))
  63. (read-from-string ans)))
  64.  
  65. (defun GET-DEFSTRUCT-NAME (instance)
  66. "Given a defstruct instance, return the symbol which is its name."
  67. (parse-defstruct-spec instance))
  68.  
  69. (defun STRUCTURE-P (X)
  70. "Vendor independent redicate: returns T if x is a structure instance!"
  71. (funcall *vendor-defstruct-predicate-function* x))
  72.  
  73. (defun GET-DEFSTRUCT-DESCRIPTOR (structname)
  74. "A vendor-independent way to get the defstruct descriptor out."
  75. (when (structure-p structname)
  76. (setf structname (get-defstruct-name structname)))
  77. (funcall *vendor-defstruct-descriptor-function* structname))
  78.  
  79. This problem is even worse for functions of the form:
  80.  
  81. (get-defstruct-copier <defstruct name>)
  82.  
  83. So when you write your dpANS comments, please advocate a more
  84. complete interface to DEFSTRUCT that suits YOUR needs!
  85.  
  86. kerry
  87.