Lisp HUG Maillist Archive

Common Lisp spec question

Is the data in an array guaranteed to stay that way for elements beyond 
the fill pointer?

Specifically, this works in LW (and CCL):

CL-USER > (setf xs (make-array 5 :initial-contents '(1 2 3 4 5) 
:fill-pointer 0))
#()

CL-USER > (aref xs (incf (fill-pointer xs)))
2

CL-USER > (aref xs (incf (fill-pointer xs)))
3

CL-USER > (aref xs (incf (fill-pointer xs)))
4

But, I don't know if this is guaranteed in the spec.

I assume it would be true as long as the array wasn't adjusted in size. 
But I don't know if an array with a fill-pointer smaller than the 
capacity of the array means the system is allowed to resize the array 
smaller or even garbage collect objects beyond the fill pointer.

Jeff M.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Common Lisp spec question

This is not from the spec, but : 

"The fill pointer is a non-negative integer no larger than the total number of elements in the vector (as returned by array-dimension); it is the number of ``active'' or ``filled-in'' elements in the vector. The fill pointer constitutes the ``active length'' of the vector; all vector elements whose index is less than the fill pointer are active, and the others are inactive. Nearly all functions that operate on the contents of a vector will operate only on the active elements. An important exception is aref, which can be used to access any vector element whether in the active region of the vector or not. It is important to note that vector elements not in the active region are still considered part of the vector.

Implementation note: An implication of this rule is that vector elements outside the active region may not be garbage-collected."

-- https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node162.html#SECTION002150000000000000000

and from the spec : "aref ignores fill pointers. It is permissible to use aref to access any array element, whether active or not." 
-- http://www.lispworks.com/documentation/lw60/CLHS/Body/f_aref.htm

-- drewc

On Wed, Jul 29, 2015 at 11:17 AM, Jeffrey Massung <massung@gmail.com> wrote:

Is the data in an array guaranteed to stay that way for elements beyond the fill pointer?

Specifically, this works in LW (and CCL):

CL-USER > (setf xs (make-array 5 :initial-contents '(1 2 3 4 5) :fill-pointer 0))
#()

CL-USER > (aref xs (incf (fill-pointer xs)))
2

CL-USER > (aref xs (incf (fill-pointer xs)))
3

CL-USER > (aref xs (incf (fill-pointer xs)))
4

But, I don't know if this is guaranteed in the spec.

I assume it would be true as long as the array wasn't adjusted in size. But I don't know if an array with a fill-pointer smaller than the capacity of the array means the system is allowed to resize the array smaller or even garbage collect objects beyond the fill pointer.

Jeff M.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Common Lisp spec question

Drew C <me@drewc.ca> writes:

> This is not from the spec, but : 
>
> "The fill pointer is a non-negative integer no larger than the total
> number of elements in the vector (as returned by array-dimension); it
> is the number of ``active'' or ``filled-in'' elements in the vector.
> The fill pointer constitutes the ``active length'' of the vector; all
> vector elements whose index is less than the fill pointer are active,
> and the others are inactive. Nearly all functions that operate on the
> contents of a vector will operate only on the active elements. An
> important exception is aref, which can be used to access any vector
> element whether in the active region of the vector or not. It is
> important to note that vector elements not in the active region are
> still considered part of the vector.
>
> Implementation note: An implication of this rule is that vector
> elements outside the active region may not be garbage-collected."
>
> -- https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node162.html#
> SECTION002150000000000000000
>
> and from the spec : "aref ignores fill pointers. It is permissible to
> use aref to access any array element, whether active or not." 

Notably, elt doesn't ignore fill pointers!

(let ((v (make-array 10 :fill-pointer 0 :initial-element 'inactive)))
  (vector-push 'active v)
  (vector-push 'active v)
  (vector-push 'active v)
  (vector-push 'active v)
  (list (aref v 3)
        (aref v 4)
        '/
        (elt v 3)
        (nth-value 1 (ignore-errors (elt v 4)))))
--> (active inactive / active #<ccl::sequence-index-type-error #x3020022E947D>)


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:33 UTC