[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 14:55 EST
    From: Daniel L. Weinreb <DLW@SCRC-QUABBIN.ARPA>

	Date: Fri, 22 Nov 85 11:55 EST
	From: Kent M Pitman <KMP@SCRC-STONY-BROOK.ARPA>

	Given:

	  (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)

    I am assuming that "in the bounds" means "less than 5".  Therefore, I am
    advocating choice number 1.  See the definition of :initial-element on
    page 297.

Oh, ok. I couldn't imagine that you were suggesting #1. I'm glad I asked.
#1 sounds fine to me.

	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 am also assuming that the fill pointer remains 3.

	I would be curious to hear an elaboration of your motivation.

    The feeling is that the programmer would reasonably expect this code to
    initialize the elements beyond the fill pointer, so that when the fill
    pointer is increased, instead of finding unpredictable junk in the
    array, the contents will be what was specified by :initial-elements.  It
    seems like the most useful definition.

Although, interestingly, in this example, elements 3 and 4 will (rightly) contain
unpredictable junk. I think we agree even though I don't think what you said 
in this paragraph is true. I believe what you meant is that in the case of:

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

he has a right to expect that information beyond element 2 will not be junk
(ie, slots 3 and 4 will contain non-junk from the MAKE-ARRAY and slots
5 and 6 will contain non-junk from the ADJUST-ARRAY).