Re: array initialisation



On Apr 29, 3:14 pm, Edi Weitz <spamt...@xxxxxxxxxx> wrote:
On Tue, 29 Apr 2008 05:36:44 -0700 (PDT), nicolas.e...@xxxxxxxxx wrote:
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 ?

How about '(or null foo) as the element type?


Beside the fact this works, this is elegant ;)
The more I learn Lisp, the more I find it consistent and powerfull.
Thank you.

-Nicolas

.



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: 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)
  • Re: remove or delete variable
    ... X instance has no attribute 'foo' ... learn that the attribute had the wrong value - at that point when someone invokes a method on nil that is not defined for NilClass. ... class ChangingFields ... def method_missing ...
    (comp.lang.ruby)