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))
; in: LAMBDA NIL
; (MAKE-ARRAY X :ELEMENT-TYPE 'FOO :INITIAL-ELEMENT NIL)
;
; caught STYLE-WARNING:
; NIL is not a FOO.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
BAR

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 ?

Like Thomas says, or:

(defun bar (x)
(make-array x :element-type '(or null foo) :initial-element nil))

which should not make much difference when foo is not a 'basic' type
like fixnum, character or double-float...

--
__Pascal Bourguignon__
.



Relevant Pages

  • Re: popold
    ... NIL ... FOO ... Elapsed time = 0:00:01 ... Page faults ...
    (comp.lang.lisp)
  • Re: Scoping Question
    ... * (setf foo 3) ... Warning: This variable is undefined: ... WARN is an external symbol in the KEYWORD package. ... NIL -- Never declare the variable, ...
    (comp.lang.lisp)
  • Re: Why if 0 succeeds in Ruby
    ... Every *comparison* with nil does fail. ... "unless foo" is not a comparison of foo with false, ... His code sample showed what he meant! ...
    (comp.lang.ruby)
  • Re: new block notation
    ... difference easy and clean, the way that it is now. ... irb:036:0> task foo do |t| p t end ...
    (comp.lang.ruby)
  • Re: array initialisation
    ... #<STANDARD-CLASS FOO> ... Now I define a function that creates an array of instances of class ... CL-USER> ... ; in: LAMBDA NIL ...
    (comp.lang.lisp)