|
Prev: Any progress on free open source Windows LISP Versions?
Next: the power of a language example: full mathematical functions buildin
From: danb on 6 May 2008 12:50 > > On May 5, 2:11 pm, Rainer Joswig <jos...(a)lisp.de> wrote: > >> Your Lisp has decided that the element type of > >> the above array is of type T. Means it > >> does not have a special array type for > >> arrays with element type INTEGER. > danb <sogwal...(a)gmail.com> writes: > > You mean it's used to choose between different > > array implementations? On May 6, 2:27 am, Pascal J. Bourguignon wrote: > No, it's an implementation introspection API. Right, my mistake. What I meant to suggest was that :element-type helps the system choose an implementation for the array, and #'array-element-type reports what the system chose. > > 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. Thanks Pascal, I appreciate the help. ------------------------------------------------ Dan Bensen http://www.prairienet.org/~dsb/ cl-match: expressive pattern matching in Lisp http://common-lisp.net/project/cl-match/
From: Pascal J. Bourguignon on 6 May 2008 13:01 danb <sogwaldan(a)gmail.com> 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. -- __Pascal Bourguignon__
From: John Thingstad on 6 May 2008 13:57 P� Tue, 06 May 2008 19:01:59 +0200, skrev Pascal J. Bourguignon <pjb(a)informatimago.com>: > danb <sogwaldan(a)gmail.com> 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. > As long as upgraded-array-element-type is t anything goes. The problem is that the array 'forgets' the original declaration and substitutes the upgraded one. For 'fixnum or something of the like which isn't upgraded to 't you would get a error for the case above. Must admit this was a real awakener for me. -------------- John Thingstad
From: Duane Rettig on 6 May 2008 16:12 pjb(a)informatimago.com (Pascal J. Bourguignon) writes: > danb <sogwaldan(a)gmail.com> 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/support/documentation/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(a)franz.com 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
From: Zach Beane on 5 May 2008 15:07
danb <sogwaldan(a)gmail.com> writes: > * (array-element-type (MAKE-ARRAY '(2) > :ELEMENT-TYPE 'INTEGER > :INITIAL-CONTENTS '(1 2))) > => T > > Why does this function exist? It doesn't seem to do much. See also the result of: (upgraded-array-element-type 'integer) vs. (upgraded-array-element-type '(unsigned-byte 8)) (UNSIGNED-BYTE 8) could be any type for which your Lisp has a specialized array representation. Zach |