CLOS problem: `initialize-instance' etc 
Author Message
 CLOS problem: `initialize-instance' etc


> (defclass z () (x))
> (defmethod initialize-instance :after ((a z) &rest junk) ... do something)
> (defun aaa-to-z (a)
>   (let ((zz (make-instance 'z)))
>     (when ......
>       (setf (slot-value z 'x) ....))))

> Unfortunately this means that when `initialize-instance :after' is
> invoked, the slot 'x is still unbound.  Aparently, I can do

> (defmethod initialize-instance :around ((a z) &rest args &key x)
>   (unless x (remf args 'x))
>   (call-next-method)
>   ... do something)

> (defun aaa-to-z (x)
>   (let ((zz (make-instance 'z 'x (when .... .....))))
>    ....))

> the problem is that this uses up NIL as a valid value for the slot X.

> What is the right way to deal with the problem?

There's key-supplied-p as posted by Barry Margolin, but there's also
shared-initialize, which initializes a given slot. You just might use that
for your slot x.

Have fun with it.


Sun, 07 Oct 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. CLOS problem: `initialize-instance' etc

2. Beginner's problems with CLOS

3. new instances from initialize

4. how to initialize instance variables?

5. Instance vars as arguments to initialize()?

6. Creating an instance of a class without calling initialize()

7. changing slots in an overloaded initialize-instance, and type checking

8. initializing instances question...

9. new class-instance is not getting initialized

10. new, initialize, etc.

11. efficient instance reallocation in CLOS

12. Finding CLOS instances


Powered by phpBB® Forum Software