Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Lisp > Re: Function AR...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 12 Topic 12427 of 13402
Post > Topic >>

Re: Function ARRAY-ELEMENT-TYPE

by Duane Rettig <duane@[EMAIL PROTECTED] > May 6, 2008 at 01:12 PM

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
 




 12 Posts in Topic:
Function ARRAY-ELEMENT-TYPE
danb <sogwaldan@[EMAIL  2008-05-05 11:50:20 
Re: Function ARRAY-ELEMENT-TYPE
Zach Beane <xach@[EMAI  2008-05-05 15:07:07 
Re: Function ARRAY-ELEMENT-TYPE
Jeronimo Pellegrini <j  2008-05-05 21:07:45 
Re: Function ARRAY-ELEMENT-TYPE
Rainer Joswig <joswig@  2008-05-05 21:11:28 
Re: Function ARRAY-ELEMENT-TYPE
danb <sogwaldan@[EMAIL  2008-05-05 13:07:34 
Re: Function ARRAY-ELEMENT-TYPE
Rainer Joswig <joswig@  2008-05-05 22:29:16 
Re: Function ARRAY-ELEMENT-TYPE
pjb@[EMAIL PROTECTED] (P  2008-05-06 09:27:53 
Re: Function ARRAY-ELEMENT-TYPE
Kent M Pitman <pitman@  2008-05-05 17:37:35 
Re: Function ARRAY-ELEMENT-TYPE
danb <sogwaldan@[EMAIL  2008-05-06 09:50:57 
Re: Function ARRAY-ELEMENT-TYPE
pjb@[EMAIL PROTECTED] (P  2008-05-06 19:01:59 
Re: Function ARRAY-ELEMENT-TYPE
"John Thingstad"  2008-05-06 19:57:59 
Re: Function ARRAY-ELEMENT-TYPE
Duane Rettig <duane@[E  2008-05-06 13:12:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 23:11:13 CDT 2008.