CLHS: Issue DISPLACED-ARRAY-PREDICATE Writeup

#

## Issue DISPLACED-ARRAY-PREDICATE Writeup

    Issue:             DISPLACED-ARRAY-PREDICATE
    References:        MAKE-ARRAY
    Related issues:    ADJUST-ARRAY-DISPLACEMENT
    Category:          ADDITION
    Edit history:      v1, 13 Feb 1991, Sandra Loosemore
                       v2, 11 Mar 1991, Sandra Loosemore
                       v3, 26 Mar 1991, Sandra Loosemore (amendment from meeting)
    Status:            v3 (proposal ADD) accepted by X3J13, Mar 91

    Problem description:

      There is no way to determine whether an array is displaced to another
      array.  Having this information available would be helpful to some
      applications that want to dump and restore array contents, either to
      allow them to detect when sharing of displaced arrays is lost or to
      reconstruct the arrays in such a way that sharing is preserved.

    Proposal (DISPLACED-ARRAY-PREDICATE:ADD):

      Add a function:

        ARRAY-DISPLACEMENT <array>                                 [Function]

        The <array> argument must be an array.  If the array is a displaced
        array, two values are returned:  the array to which it is displaced
        corresponding to the :DISPLACED-TO argument to MAKE-ARRAY, and an
        integer corresponding to the :DISPLACED-INDEX-OFFSET argument to
        MAKE-ARRAY.  If the array is not a displaced array, this function
        returns two values NIL and 0.

        If ARRAY-DISPLACEMENT is called on an array for which a non-NIL
        object was provided as the :DISPLACED-TO argument to MAKE-ARRAY
        or ADJUST-ARRAY, it must return that object as its first value.
        It is implementation-dependent whether ARRAY-DISPLACEMENT returns
        a non-NIL first value for any other array.

    Examples:

      (array-displacement '#(1 2 3))
        => the values are not specified, but are probably NIL and 0 in many
           implementations.
      (array-displacement (make-array 2 :displaced-to '#1=#(1 2 3)))
        => (values #1# 0)

    Rationale:

      Providing the function solves the problem.

      Some implementations implicitly displace some arrays.  (For example,
      adjustable arrays might be represented as displaced arrays.)  Permitting
      ARRAY-DISPLACEMENT to return non-NIL for those arrays allows those
      implementations not to have to record some additional information
      in the array about whether an explicit :DISPLACED-TO was provided.

    Current Practice:

      Lucid version 4.0 and Apple's Macintosh Common Lisp implement such
      a function, but call it DISPLACED-ARRAY-P.

      Symbolics has an ARRAY-DISPLACED-P predicate but it returns neither
      the array nor an index, just a boolean.

    Cost to Implementors:

      It's probably easy to add.

    Cost to Users:

      None, this is a new feature.

    Cost of non-adoption:

      Users can't do some kind of manipulations on displaced arrays in a
      portable way.

    Performance impact:

      Probably none.

    Benefits:

      The cost of non-adoption is avoided.

    Esthetics:

      Looks OK to me.

    Discussion:

      The addition of such a function was mentioned in the writeup for
      proposal ADJUST-ARRAY-DISPLACEMENT as something that had been
      considered at that time.  I don't recall what the arguments were
      against it.

      A more extreme proposal would also define ARRAY-DISPLACEMENT as
      a SETF place, to allow these parameters of displaced arrays to
      be changed.

      The original name suggested for this function was DISPLACED-ARRAY-P.

      JonL notes:

        The reason Lucid has DISPLACED-ARRAY-P is that is the name Guy Steele
        gave it back it 6-Dec-85 -- the "Clarifications" and
        "non-controversial ..." lists.  Quite possibly, it had been suggested
        already in the common-lisp@su-ai forum.

Copyright 1996-2005, LispWorks Ltd. All rights reserved.