pjb@[EMAIL PROTECTED]
(Pascal J. Bourguignon) writes:
> danb <sogwaldan@[EMAIL PROTECTED]
> writes:
>>> > So there's no way to automatically create type
>>> > declarations for all the elements of an array?
>>> > That's what I thought :element-type would do.
>>
>>> Yes, that's what :element-type does.
>>
>> Not quite. I thought it would do the equivalent of
>> (declaim (desired-type (aref my-array <indices>)))
>>
>> for each element in the array, but apparently that
>> wouldn't be allowed anyway. The only type error
>> I've seen sbcl generate from :element-type is in
>> the array's *initial* contents, not when I change
>> the contents later.
>>
>>> (let ((a (make-array '(1)
>> :element-type 'string
>> :initial-contents '("FOO"))))
>> (setf (aref a 0) :foo)
>> a)
>> #(:FOO)
>>
>> This even works inside a compiled function.
>> I thought it would generate an error.
>
> Indeed, I would have expected too an error at leat with (safety 3)...
>
> telnet://prompt.franz.com too has the same behavior.
Note that the descrtiption of array-element-type:
http://www.franz.com/sup****t/do***entation/current/ansicl/dictentr/array-el.htm
says "Returns a type specifier which represents the actual array
element type of the array, which is the set of objects that such an
array can hold. (Because of array upgrading, this type specifier can
in some cases denote a supertype of the expressed array element type
of the array.)"
So the example above represents the expectation that the compiler would
use the "expressed element type" as the declaration, rather than the
"actual element type". This might be a reasonable request, except
that it places a larger burden on type checking when setfs are done on
the array, especially for interpreted code. When you ask for an array
a of (unsigned-byte 7) and get one back which is (unsigned-byte 8),
should (setf (aref a 0) 255) result in an error? It would defeat one
of the purposes of having specialized arrays, which is the quick
testing of values to set. So the answer is no: (setf aref) uses the
actual element type to determine limits.
--
Duane Rettig duane@[EMAIL PROTECTED]
Franz Inc. http://www.franz.com/
555 12th St., Suite 1450 http://www.555citycenter.com/
Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182


|