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


    I have also done some thinking about types in connection with my
project of writing a Common Lisp compiler that takes types seriously.
I tend to agree Sandra that your example demonstrates a problem in the
type system rather than a solution.  Unless you have a better example,
what you are really demonstrating is the horrible lossage in the
definition of specialized array types.

    I agree that it might be useful to be able to determine if an
object can be stored in an array, but I suggest that the problem be
solved by adding an Array-Can-Hold-P predicate.  The problem is that
in principle, there is no reason why the "type" of object that can be
stored in a specialized array must be representable with a Common Lisp
type specifier.  I guess that with your
ARRAY-POSITIVE-POWER-OF-TWO-BIGNUM example, you were suggesting that
it is always possible to do the back-mapping without losing
information, but I don't think that it is a good idea to require this.

    Much of the confusion revolves around the lack of distinction
between types and objects.  When the implementation decides to
create an instance of a type, it chooses a representation.  This
mapping between types and representations is neither injective nor
surjective.  The implementation may decide to discard information, as
in (ARRAY SYMBOL) ==> (ARRAY T).  It may also decide to add
information, as in INTEGER ==> FIXNUM.

    Many functions in the language use the to-implementation mapping;
I believe that only Type-Of and Array-Element-Type attempt to perform
the from-implementation mapping.  If these functions are ignored, then
implementation's freedom to choose representations is totally
invisible, and is restricted only by the requirements that certain
types "are disjoint".

    I think that any attempt to use Type-Of or Array-Element-Type in
code is highly suspect.  The only such use that I know of is to find the
type of an object which is known to be a structure; this is presumably
what Class-Of does.  Note that in this case, Type-Of is actually doing
something totally different from what it normally does: it is making
no attempt to return the "most specific type"; instead it is making a
well-defined from-implementation mapping based on an explicitly
defined type hierarchy.  If we treated objects other than structures
the same way, then we could make a similar back-mapping for them.
This capability seems to be what Ida seems to be interested in, but it
isn't what Type-Of does.