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

TYPE-OF-UNDERCONSTRAINED, version 4



This is a proposal to amend version 3, passed as amended (to include
RANDOM-STATE) in January 1989 in Kauai.

Version 4 amends version 3 to add SHORT-FLOAT, LONG-FLOAT, and RATIONAL
to the list of types in part (a) of the proposal.


Forum:	Cleanup
Issue:      TYPE-OF-UNDERCONSTRAINED

References: TYPE-OF (CLtL)
            88-002R (Class-of)
            88-005, p 43f, Condition system types
Related issues: SUBTYPEP-TOO-VAGUE
                DATA-TYPE-HIERARCHY-UNDERSPECIFIED
                FUNCTION-TYPE
                ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS
                COERCE-INCOMPLETE
			

Category:       CLARIFICATION/CHANGE

Edit history:   Version 1,  1-Dec-88, Masinter
		    Version 2,  9-Dec-88, Masinter
		    Version 3, 12-Dec-88, Masinter (fix "egregious bug")
		Versino 4, 3-14-89 Steele
Problem description:

The specification of TYPE-OF in CLtL is so weak as to leave it 
nearly useless, if any implementor actually took the specification
seriously.In particular, there are almost no constraints on the
value that TYPE-OF might return for any of the built in
types. The only constraint placed is that for objects created by the
constructor function of DEFSTRUCT, the result of TYPE-OF is the name of the
defstruct.

This means that implementations could return T for all other objects.

Proposal (TYPE-OF-UNDERCONSTRAINED:ADD-CONSTRAINTS): 

Specify that the result of TYPE-OF satisfies the following:

(a) For any object for which (typep object built-in-type) is true when
built-in-type is one of 

INTEGER, RATIO, FLOAT, SINGLE-FLOAT, DOUBLE-FLOAT, COMPLEX, NUMBER
SYMBOL, 
STRING, VECTOR, ARRAY, RANDOM-STATE
CONS, 
STREAM, PACKAGE, CHARACTER, FUNCTION, READTABLE, HASH-TABLE, PATHNAME,
CONDITION, RESTART,
RATIONAL, SHORT-FLOAT, LONG-FLOAT

the result of TYPE-OF will be a type specifier for which
(subtypep (type-of object) built-in-type) returns T T, i.e., either the
build-in-type or a subtype of it (a subtype that the 
implementation's SUBTYPEP can recognize.)

(b)  For all objects, (TYPEP object (TYPE-OF object)) will be true.
(this implies that it will not be NIL, since no
object is of type NIL.)

(c) will not be a MEMBER type specifier, or T.

For objects created by the "constructor" function of a structure
defined with DEFSTRUCT without a :TYPE option, TYPE-OF
will return the structure name.

For objects created by MAKE-INSTANCE, giving a named
class, TYPE-OF will return the class name of the class.
 
For objects which are instances of anonymous classes (i.e., where
(CLASS-NAME (CLASS-OF object)) is NIL), the result of TYPE-OF should be the
class object itself.

(The CLOS specification has already specified that class objects are
acceptable wherever type specifiers are, and in particular, as input to
SUBTYPEP and TYPEP.)

This proposal is intended to be consistent with 88-002R, 
and not to conflict with any of the definitions in that document.

Examples:

It is legal for (TYPE-OF "abc") to return (SIMPLE-STRING 3), or just
STRING. It is legal for (TYPE-OF 112312) to return SI:MEDIUM-SIZE-FIXNUM,
as long as (SUBTYPEP 'SI:MEDIUM-SIZE-FIXNUM 'INTEGER).

 Given:

   (defvar *foo* (make-array 5 :element-type t))
   (class-name (class-of *foo*))  =>  SIMPLE-VECTOR
  It is legal for
   (type-of *foo*)                =>  (SIMPLE-VECTOR 5)


Rationale:

The original specification for "TYPE-OF" was written to allow
implementation freedom, but the wording is in fact more vague than was
intended. 

Current practice:

Most Common Lisp implementations seem to implement the proposal, at least
for the types we've tried them on.

Cost to Implementors:

Even if there are implementations that do not currently implement the
proposal, the required changes for them are likely to be minimal. 

Cost to Users:

Apparently none.

Cost of non-adoption:

TYPE-OF would remain potentially inconsistent.

Performance impact:

Likely none.

Benefits:

Bring the specification of TYPE-OF in like with its common
implementation, while requiring it to be generally useful.

Esthetics:

Little effect.

Discussion:

Originally, TYPE-OF was concieved as being useful for information display.
CLOS specified CLASS-OF far more precisely, in that it must return exactly
the class of an object. Unless TYPE-OF is removed from the language, it
seems reasonable to require it to be at least as precise as CLASS-OF.

The accepted CLOS specification does not define CLASS-OF
in terms of TYPE-OF, but an earlier draft did. 

This proposal presumes the (passed) proposals
DATA-TYPES-HIERARCHY-UNDERSPECIFIED:DISJOINT, FUNCTION-TYPE, and
accomodates the Condition System (version 18) and CLOS.

If ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS does not pass, 
and this proposal does pass, it may be that the only way an 
implementation can satisfy (TYPEP array (TYPE-OF array))
would be to have (TYPE-OF array) return VECTOR or ARRAY
as appropriate, i.e., with no element type qualification.

It is possible to constrain TYPE-OF further, e.g., to eliminate
the possibility that it might return a non-portable 
implementation-specific value. For example, 
(TYPE-OF 112312) should not return SI:MEDIUM-SIZE-FIXNUM, but rather some
thing like (SIGNED-BYTE 17) [if that's what SI:MEDIUM-SIZE-FIXNUM means.]

We would like to make this as an implementation recommendation,
however, rather than as a constraint, at this point.