Re: array initialisation



nicolas.edel@xxxxxxxxx writes:

Suppose I define a class foo
CL-USER> (defclass foo () ())
#<STANDARD-CLASS FOO>

Now I define a function that creates an array of instances of class
'foo.
CL-USER> (defun bar (x)
(make-array x :element-type 'foo :initial-element
nil))
....
I get a warning (that I could ignore) since NIL is indeed not an
instance of the FOO class.
How to create such an array with an initial value that allows me to
test whether one of its element has already been instanciated or not ?

Well, there's always:

(defconstant +NULL-FOO+ (make-instance 'foo))

(defun bar (x)
(make-array x :element-type 'foo :initial-element +NULL-FOO+))

(eq (aref (bar 10) 3) +NULL-FOO+)



--
Thomas A. Russ, USC/Information Sciences Institute
.



Relevant Pages