[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Here is an explanation of the proper role of COERCE wrt arrays:

My "treat arrays as sequences" proposal was intended to do more than just
extend the applicability of the sequence functions to arrays.  It was also
supposed to change the feel of arrays in the language, by implying that shape
isn't all that important; content is what matters.

To preserve the primacy of content, no matter what shape a sequence has (list,
vector, or n-dimensional array), we should be able to convert it to some other
shape and have the behavior of FIND, POSITION, LENGTH, ELT, etc., stay the
same.  Looked at this way, it's perfectly obvious that if ARR is a 3x3 array,
then (COERCE 'LIST ARR) should return a nine element list, not a triple of

As for going from lists to arrays, I suggest that

  (COERCE '(ARRAY dims) SEQ)

should be equivalent to


Note that SEQ may be any type of sequence, including an array; its elements
will be extracted in row-major order as if ELT were used.  This definition also
preserves the results of ELT, FIND, POSITION, etc., as long as the source and
destination objects have the same LENGTH.  If the source is longer, its
extra elements are lost; if the destination is longer, its extra elements
have undefined initial values.

-- Dave