|
From: Pascal B. <pj...@in...> - 2003-05-07 13:44:13
|
Christophe Rhodes writes: > > I understand that UPGRADED-ARRAY-ELEMENT-TYPE is implementatio= n > > dependant, but why does sbcl upgrade a (ARRAY BASE-CHAR) to T and no= t > > to (ARRAY BASE-CHAR) ? >=20 > Because the implementation does not provide a representation of arrays > specialized to holding arrays of BASE-CHAR. Further thinking on this point, I believe that there's a confusion between the representation (and UPGRADED-ARRAY-ELEMENT-TYPE seems to speak about that), and the semantic. Type inferences and assertions should be about semantics. That is: of course, I understand that an array containing arrays would be implemented as an array of pointers, so it could as well have elements of any kind. But when the programmer assert that this array is (array (array character *) *), he says that he's only considering arrays of arrays of characters, even if that kind of array could, with the same implementation, hold other things. > As an example: consider the type (SINGLE-FLOAT 0.0 1.0). If you ask > sbcl to create an array :ELEMENT-TYPE '(SINGLE-FLOAT 0.0 1.0), it will > give you back an array specialized to hold general SINGLE-FLOATs, the > layout of which looks something like this in memory: >=20 > [ header | length | element0 | element1 | element2 ] >=20 > where the element<n>s are unboxed single floats (i.e. they don't have > any header; they are just the bare IEEE single float in bits). This > is what is meant by a specialized array on some type. Yes, but the type inference engine should remember that elements of this array are always between 0.0 and 1.0, and could apply this knowledge to (AREF (THE (ARRAY (SINGLE-FLOAT 0.0 1.0) PROBS) 0). > You might wish to consider what you would need to do to provide a > specialization of array to hold objects of type (ARRAY BASE-CHAR). I think that since objects of type (ARRAY BASE-CHAR *) may be of different sizes, an array of such objects needs to be an array of pointers to them. An (ARRAY (ARRAY BASE-CHAR 10) *) could put the BASE-CHAR inline: [ header | length |t|e|n|c|h|a|r|a|c|t|t|e|n|c|h|a|r|a|c|t|...] The point is that while a (ARRAY (ARRAY BASE-CHAR *) *) has to be implemented as an (ARRAY T *), it must not forget that it contains actually (ARRAY BASE-CHAR *). > > Is there a declaration I could add to specify that all the elements o= f > > my array are of type (ARRAY BASE-CHAR) ? >=20 > No. >=20 > > Would adding THE (ARRAY CHARACTER *) in the right places do? >=20 > Yes. --=20 __Pascal_Bourguignon__ http://www.informatimago.com/ ---------------------------------------------------------------------- Do not adjust your mind, there is a fault in reality. |