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

Issue ADJUST-ARRAY-DISPLACEMENT



Status: Minor edits for presentation. No disagreement in committee.
Ready for release? (use ballot).

Issue:        ADJUST-ARRAY-DISPLACEMENT
Reference:    Steele p.297
Category:     Clarification
Edit history: Revision 1 by SEF, 18-Apr-87 (from Steele's list)
              Revision 2 by Masinter (minor)

Problem Description:

The interaction of Adjust-Array and displacement is insufficiently
specified in the case where the array being adjusted is displaced.

Proposal: ADJUST-ARRAY-DISPLAYCEMENT:RULES

Suppose we are adjusting array A, which is perhaps displaced to B before
the Adjust-Array call and perhaps to C after the call.

(1) A is not displaced before or after: The dimensions of A are altered,
and the contents rearranged as appropriate.  Additional elements of A
are taken from the :initial-element.  The use of :initial-contents
causes all old contents to be discarded.

(2) A is not displaced before, but is displaced to C after.  As
specified in CLtL, none of the original contents of A appears in A
afterwards; A now contains the contents of C, without any rearrangement
of C.

(3) A is displaced to B before the call, and is displaced to C after the
call.  As in case (2), the contents of B do not appear in A afterward
(unless such contents also happen to be in C).  If
:displaced-index-offset is not specified in the Adjust-Array call, it
defaults to zero; the old offset (into B) is not retained.

(4) A is displaced to B before the call, but not displaced afterward.  A
gets a new "data region", and contents of B are copied into it as
appropriate to maintain the existing old contents; additional elements
of A are taken from the :initial-element.  However, the use of
:initial-contents causes all old contents to be discarded.

Note that if array X is displaced to array Y, and array Y is displaced
to array Z, and array Y is altered by Adjust-Array, array X must now
refer to the adjusted contents of Y.  This means that an implementation
may not collapse the chain to make X refer to Z directly and forget that
the chain of reference passes through array Y.  (Cacheing techniques are
of course permitted, as long as they preserve the semantics specified
here and in CLtL.)

If X is displaced to Y, it is an error to adjust Y in such a way that it
no longer has enough elements to satisfy X.  This error may be signalled
at the time of the adjustment, but this is not required.

Rationale:

This interaction must be clarified.  This set of rules was proposed some
time ago, as a result of discussions on the Common Lisp mailing list,
and this model has been adopted by many Common Lisp implementations.

Current Practice:

Many implementations currently follow the model proposed here.  Others
may do something random.  [See discussion below.]

Adoption cost:

Some existing implementations may have to be changed, but adopting any
other model would be worse.  Public-domain code implementing this model
is available from CMU.

Benefits:

Clarification of a situation that is currently not addressed by the
standard.

Conversion Cost:

This is a relatively uncommon situation, which is the reason it didn't
occur to the original language designers to specify how it works.  Any
user code that cares about this issue probably already follows the
proposed model.

Discussion:

Discussed long ago on the Common Lisp mailing list.  This proposal
attempts to capture the overall consensus that emerged at that time.

Moon: We [Symbolics] implement what is proposed, except for 

    (4) A is displaced to B before the call, but not displaced
afterward.  A
    gets a new "data region", and contents of B are copied into it as
    appropriate to maintain the existing old contents; additional
elements
    of A are taken from the :initial-element.

We never copy the contents of B in this case; all elements are taken
 from the :initial-element.

Either behavior seems equally justifiable to me.  One could say
"adjust-array never stores into the array if it ends up displaced" or
"adjust-array only preserves the elements of non-displaced arrays."  I
have no information as to whether it matters to users.