array-has-fill-pointer-p
array-has-fill-pointer-p Function
Syntax:
array-has-fill-pointer-p array → generalized-boolean
Arguments and Values:
array—an array.
generalized-boolean—a generalized boolean.
Description:
Returns true if array has a fill pointer ; otherwise returns false.
Examples:
(array-has-fill-pointer-p (make-array 4)) → implementation-dependent
(array-has-fill-pointer-p (make-array ’(2 3))) → false
(array-has-fill-pointer-p
(make-array 8
:fill-pointer 2
:initial-element ’filler)) → true
Exceptional Situations:
Should signal an error of type type-error if its argument is not an array.
See Also:
make-array, fill-pointer
Notes:
Since arrays of rank other than one cannot have a fill pointer , array-has-fill-pointer-p always returns nil when its argument is such an array.
Expanded Reference: array-has-fill-pointer-p
Basic Usage
array-has-fill-pointer-p returns true if the array has a fill pointer, false otherwise.
(array-has-fill-pointer-p (make-array 5 :fill-pointer 0))
=> T
(array-has-fill-pointer-p (make-array 5 :fill-pointer 3))
=> T
;; Fill pointer set to T (equals total size)
(array-has-fill-pointer-p (make-array 5 :fill-pointer t))
=> T
Arrays Without Fill Pointers
Simple arrays created without :fill-pointer may or may not have a fill pointer, depending on the implementation.
;; Multi-dimensional arrays never have fill pointers
(array-has-fill-pointer-p (make-array '(2 3)))
=> NIL
;; Strings and bit vectors as literals typically do not
(array-has-fill-pointer-p "hello")
=> NIL
Guarding fill-pointer Calls
Use array-has-fill-pointer-p before calling fill-pointer to avoid errors.
(defun safe-fill-pointer (array)
"Return the fill pointer if present, or NIL."
(when (array-has-fill-pointer-p array)
(fill-pointer array)))
(safe-fill-pointer (make-array 5 :fill-pointer 3))
=> 3
(safe-fill-pointer (make-array 5))
=> NIL
Only Vectors Can Have Fill Pointers
Arrays of rank other than 1 never have fill pointers.
(list (array-has-fill-pointer-p (make-array '(3 4)))
(array-has-fill-pointer-p (make-array '(2 3 4)))
(array-has-fill-pointer-p (make-array '())))
=> (NIL NIL NIL)