[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Quick CL Array question
Date: Thu, 26 Nov 1992 16:08-0000
From: Guy Footring <Guy@AVON.sltd.dialnet.symbolics.com>
Anyone care to give an opinion on why Common Lisp allows array dimensions to be 0?
It's a common boundary case, and there's no reason to disallow it
Since such an array has no elements there is no way to store values into or retrieve values from it.
Is the feature simpy intended to be used for adjustable arrays with the intent that the array really
is adjusted before being used?
Zero-length axes generally occur when the axis is iterated over. When the
length is 0, the iteration will always exit immediately, so there will
never be any attempts to access the array contents, so the lack of any
array elements shouldn't be a problem.
While I'm on the topic, is the following how zero-dimension arrays are intended to be used?
(defvar *one-elt-array* (make-array nil))
(setf (aref *one-elt-array*) 'the-only-value)
Yes. Again, zero-dimension arrays are just a boundary case. I'd expect
them to occur when the number of dimensions is determined at run time, and
the array is accessed with something like (apply #'aref array index-list).