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

ADJUST-ARRAY



    Date: Thu, 16 Oct 86 00:40 EDT
    From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM>

    CLtL (p297) says that it is "not permitted to call ADJUST-ARRAY on an
    array that was not created with the :ADJUSTABLE option." This strikes me
    as overly restrictive. Why don't we say that ADJUST-ARRAY always returns
    an adjusted array and that the argument array will be modified only if
    (ADJUSTABLE-ARRAY-P array) was true. This is no more unreasonable than
    the current specification for the DELETE function.

I suspect people rely on arrays as updatable objects with identity a lot more
often than they rely on lists that way.  In other words, if ADJUST-ARRAY
sometimes quietly returns a new array and leaves the old one unadjusted,
there are likely to be other references to the old array that don't get
updated, and hence there will be bugs.

I always argued for making all arrays adjustable, for this reason.  Given
that we can't have that, I think your behavior is reasonable but it should
not be the default because it could lead to undetected bugs.

    I have an application where this comes up and as nearly as I can tell,
    I must now go and simulate the effect of ADJUST-ARRAY in order to create
    an array to a new size and make sure it gets filled properly. It makes me
    sad that I should have to do this when there's a function already that 
    comes so close to what I want.

This is a good argument.  This is a typical example of where Common Lisp went
wrong by standardizing a new, untried idea instead of standardizing current
practice, which would be okay except that what was standardized was a bundle
of several primitives and the underlying primitives were not exposed, so that
users can't easily define functions to hide the deficiencies they feel are
present in the standardized bundle.

I think there should be a new keyword argument to ADJUST-ARRAY that does
what you want, or else a separate function for this purpose, as there
was in Zetalisp (ARRAY-GROW).  I don't think the default behavior of
ADJUST-ARRAY should be changed, for reasons given above.  I can't think
of any good names for the keyword argument; the best I was able to come
up with was :IF-NOT-ADJUSTABLE with values :ERROR and :COPY.