From: Spiros Bousbouras on 3 Dec 2009 18:29 1. (setq *PRINT-ARRAY* t) (make-array 1) Is this undefined behavior ? 2. Why the requirement that the dimensions of an array are fixnums ? 3. Even if there is good reason that the dimensions of an array be fixnums you cannot do (make-array most-positive-fixnum) but the most you can do is (make-array (1- most-positive-fixnum)) because the page for ARRAY-DIMENSION-LIMIT says that it's a fixnum and "The upper exclusive bound on each individual dimension of an array". Why not make it an inclusive bound ? -- Judicial punishment is revenge abstracted.
From: Pascal J. Bourguignon on 3 Dec 2009 19:10 Spiros Bousbouras <spibou(a)gmail.com> writes: > 1. (setq *PRINT-ARRAY* t) > (make-array 1) > > Is this undefined behavior ? No, it is implementation dependant, but not undefined. > 2. Why the requirement that the dimensions of an array are fixnums ? Why not? This is not a big restriction, if an implementation wants bigger arrays, it only has to provide bigger fixnums. Really, the reason is that Common Lisp is not purely a high level programming language, it is specified in such a way that implementation can easily be efficient. If you allowed bignums as index for arrays, each AREF would imply a bignum multiplication, which would be slow. Moreover, there would be no point, because in general the size of arrays slots is one word, and fixnum is all you need to index all the words you can store in memory. (eg. with a 32-bit processor, a fixnum of 30-bit is enough to index the whole memory. Why would you want a bigger index?). > 3. Even if there is good reason that the dimensions of an array be > fixnums you cannot do (make-array most-positive-fixnum) but the most > you can do is (make-array (1- most-positive-fixnum)) because the page > for ARRAY-DIMENSION-LIMIT says that it's a fixnum and "The upper > exclusive bound on each individual dimension of an array". Why not make > it an inclusive bound ? (0 1 2 3 4) How many elements? -- __Pascal Bourguignon__
From: Pascal J. Bourguignon on 3 Dec 2009 19:16 pjb(a)informatimago.com (Pascal J. Bourguignon) writes: > Spiros Bousbouras <spibou(a)gmail.com> writes: > >> 1. (setq *PRINT-ARRAY* t) >> (make-array 1) >> >> Is this undefined behavior ? > > No, it is implementation dependant, but not undefined. Oops, sorry, indeed it's undefined. That's what you get for asking to a human instead of reading the reference! >> 2. Why the requirement that the dimensions of an array are fixnums ? > > Why not? This is not a big restriction, if an implementation wants > bigger arrays, it only has to provide bigger fixnums. > > Really, the reason is that Common Lisp is not purely a high level > programming language, it is specified in such a way that > implementation can easily be efficient. If you allowed bignums as > index for arrays, each AREF would imply a bignum multiplication, which > would be slow. Moreover, there would be no point, because in general > the size of arrays slots is one word, and fixnum is all you need to > index all the words you can store in memory. (eg. with a 32-bit > processor, a fixnum of 30-bit is enough to index the whole memory. > Why would you want a bigger index?). > > >> 3. Even if there is good reason that the dimensions of an array be >> fixnums you cannot do (make-array most-positive-fixnum) but the most >> you can do is (make-array (1- most-positive-fixnum)) because the page >> for ARRAY-DIMENSION-LIMIT says that it's a fixnum and "The upper >> exclusive bound on each individual dimension of an array". Why not make >> it an inclusive bound ? > > (0 1 2 3 4) How many elements? -- __Pascal Bourguignon__
From: Kaz Kylheku on 3 Dec 2009 19:35 On 2009-12-04, Pascal J. Bourguignon <pjb(a)informatimago.com> wrote: >> for ARRAY-DIMENSION-LIMIT says that it's a fixnum and "The upper >> exclusive bound on each individual dimension of an array". Why not make >> it an inclusive bound ? > > (0 1 2 3 4) How many elements? Wrong. The bound is on the dimension, which is the number of elements, not on the index of the highest element. So if the array-dimension-limit is 5, it being exlusive means that you can make an array that has up to 4 elements, which are addressed from 0 to 3. Why array-dimension-limit is an exclusive limit is probably for historic reasons. Maybe when Lisp was standardized, implementations did not agree whether or not this limit is inclusive or exclusive. If implementations don't agree about a parameter like this, what can you recommend to programmers? Treat it as exclusive, of course! That's the weaker, more portable assumption. Or maybe all of the implementations had the exclusive behavior, which would have been codified as-is.
From: Pascal J. Bourguignon on 3 Dec 2009 19:46
Kaz Kylheku <kkylheku(a)gmail.com> writes: > On 2009-12-04, Pascal J. Bourguignon <pjb(a)informatimago.com> wrote: >>> for ARRAY-DIMENSION-LIMIT says that it's a fixnum and "The upper >>> exclusive bound on each individual dimension of an array". Why not make >>> it an inclusive bound ? >> >> (0 1 2 3 4) How many elements? > > Wrong. The bound is on the dimension, which is the number of elements, not on > the index of the highest element. So if the array-dimension-limit is 5, > it being exlusive means that you can make an array that has up to 4 elements, > which are addressed from 0 to 3. > > Why array-dimension-limit is an exclusive limit is probably for historic > reasons. > > Maybe when Lisp was standardized, implementations did not agree whether or not > this limit is inclusive or exclusive. If implementations don't agree about a > parameter like this, what can you recommend to programmers? Treat it as > exclusive, of course! That's the weaker, more portable assumption. > > Or maybe all of the implementations had the exclusive behavior, which > would have been codified as-is. And again, once you have filled the memory with your array, you need at least one word to store the only instruction that can make you program up, so there's no point in going to fixnum+1. -- __Pascal Bourguignon__ |