[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issue: STRUCTURE-INFO (Version 1)



Please be sure to cc Dick@WHEATIES.AI.MIT.EDU in any correspondence
on this issue since he's not on CL-Cleanup.
 -kmp

----------
Issue:        STRUCTURE-INFO
References:   Structures (pp305-320)
Category:     ADDITION
Edit history: 24-Jun-88, Version 1 by Pitman and Waters
Status:	      For Internal Discussion

Problem Description:

  There is no portable way to determine whether something is a structure
  and no portable way to ask abstractly what the contents of a structure
  are without understanding that particular structure.

Proposal (STRUCTURE-INFO:NEW-FUNCTIONS):

  Introduce these new functions:

   STRUCTUREP thing					[Function]

    Predicate returns true if the given object is represented as
    a structure (without the use of DEFSTRUCT's :TYPE option).
    Otherwise, returns false.

   STRUCTURE-CONTENTS structure 			[Function]

    Returns an alist of field names (as keywords) and field values showing
    the contents of the STRUCTURE. The STRUCTURE may be any object
    for which STRUCTUREP returns true.

Test Case:

  (DEFSTRUCT (FRED (:TYPE VECTOR)) (A 1) (B 2) (C 3))
  (SETQ FRED (MAKE-FRED))
  (STRUCTUREP FRED) => NIL
  (VECTORP FRED) => T
  (STRUCTURE-CONTENTS FRED) is undefined

  (DEFSTRUCT WILMA (A 1) (B 2) (C 3))
  (SETQ WILMA (MAKE-WILMA))
  (STRUCTUREP WILMA) => T
  (STRUCTURE-CONTENTS WILMA) => ((:A . 1) (:B . 2) (:C . 3))

Rationale:

  STRUCTUREP is important for implementing a portable pretty printer in
  a number of ways.  STRUCTURE-CONTENTS is less important, but is necessary
  if a portable pretty printer is to print structures in #S notation.

Current Practice:

  Some implementations, such as Symbolics Genera, provide
   (TYPEP x 'STRUCTURE).
  Most implementations do not go so far as to provide STRUCTUREP, however.

  Probably no implementations offer STRUCTURE-CONTENTS in any exported form.

Cost to Implementors:

  Since the standard printer must access this same information when 
  printing structures, it must be very trivial to provide this functionality.

Cost to Users:

  None. This is an upward compatible change.

Cost of Non-Adoption:

  Portable pretty printers would not be able to pretty-print structure
  objects in #S notation.

Benefits:

  In addition to pretty printers, this might be of some use to programmers
  customizing the generic function DESCRIBE, or to people writing
  DESCRIBE-like facilities.

Aesthetics:

  No major aesthetic impact.

Discussion:

  Dick Waters submitted a request for changes of this kind in a letter to
  X3J13 dated June 14, 1988. Pitman wrote up the request formally.

  If the CLOS meta-object protocol becomes a standard part of CL, this
  facility would not be necessary.  However, if that protocol is in any way
  optional, it would be useful to have this interface since it can be
  implemented using considerably less powerful primitives than that
  protocol offers.