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

Fill-pointers and sequences



    Date: Thu, 21 Nov 85 10:42 EST
    From: Guy Steele <gls@THINK-AQUINAS.ARPA>

    There are two other passages you might consider.  First, page 246, last
    paragraph, states that the :start and :end arguments should be integer
    indices "into the sequence"; is an index larger than the fill pointer
    "into the sequence" or merely "into the vector"?  Second, page 291 notes
    that "aref is unusual among the functions that operate on arrays in that
    it completely ignores fill pointers".  If we really believed the book to
    be careful and accurate, we might infer that other functions not
    specifically documented to be in this unusual category may not access
    beyond the fill pointer; but in the actual event this inference is shaky
    at best.

    I think I would be inclined to write the code in this manner:

      (setq a (make-array 10 :fill-pointer 3))

      (let ((old-fill-pointer (shiftf (fill-pointer a) (array-total-size a))))
	(fill a nil :start (fill-pointer a) :end (array-dimension a 0))
	(setf (fill-pointer a) old-fill-pointer))

    or, for the truly worried,

      (let ((old-fill-pointer (array-total-size a)))
	(unwind-protect
	    (progn (setf (fill-pointer a) (array-total-size a))
		   (fill a nil :start (fill-pointer a) :end (array-dimension a 0)))
	  (setf (fill-pointer a) old-fill-pointer)))

    I do not feel strongly about which way this issue is resolved, but I
    agree that it should be tied down.  I mildly favor a strict interpretation.

Okay, but I have to ask what we gain by making the user go through this 5-line
rigamarole when a simple call to FILL would suffice if the language were defined
the other way.  To me, the fill-pointer is simply the current length and doesn't
mean that the rest of the vector does not exist in any sense (see the note on
p.295 that vector elements not in the active region are still part of the vector).
I guess the language is going to be ugly either way.

I also want to repeat my query which no one addressed yet: Does the answer
depend on whether the sequence function in question is one that writes
(like FILL or REPLACE) or one that reads (like POSITION or REMOVE)?