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

adjust-array with :initial-elements and fill pointers

    Date: Fri, 22 Nov 85 10:36 EST
    From: Daniel L. Weinreb <DLW@SCRC-QUABBIN.ARPA>

    Consider the following forms:

      (setq a (make-array 5 :fill-pointer 3))
      (adjust-array a 7 :initial-element 'b)

    What should happen?  On page 297, it says "The elements of the new array
    that are not in the bounds of array are initalized to the
    :initial-element".  The question is whether the elements that follow the
    fill pointer are considered to be within the "bounds of the array".  The
    sentence on page 295, "Nearly all functions that operate on the contents
    of a vector will operate only on the active elements", is what makes
    this issue less than perfectly clear.

    Our recommendation is that the entire new array be initialized, despite
    the presence of the fill pointer, and that adjust-array be clearly
    designated as one of the exceptions to the "nearly all" phrase.


  (setq a (make-array 5 :fill-pointer 3))
  (setf (aref a 0) 'x)
  (setf (aref a 2) 'z)
  (adjust-array a 7 :initial-element 'b)

Which of the following are you proposing:

  1.  A = [ X ? Z ? ? B B ]
  2.  A = [ X ? Z B B B B ]
  3.  A = [ X B Z B B B B ]
  4.  A = [ B B B B B B B ]
  5.  Other (please specify)

CLtL doesn't seem to say what happens to the fill pointer if there was no fill 
pointer specified in the ADJUST-ARRAY call but there was one specified to 
MAKE-ARRAY. I assume the implication is that the fill pointer remains 3. (GLS 
or Scott should correct me if I'm wrong). DLW, I am not clear on whether you 
are suggesting that it it be reset (ie, that it be the same as specifying 
:FILL-POINTER NIL or :FILL-POINTER T). Can you elaborate?

I would be curious to hear an elaboration of your motivation. In my mind, there
are reasons for believing any of these are reasonable -- depending on the 
application, which suggests to me that finer control (ie, more keywords) rather
than some arbitrary decision may be the really right thing. Of course, the 
default must be clarified in any case.