From: Marc Battyani
Subject: MOP and update-instance-for-redefined-class
Date: 
Message-ID: <61F972513F467A67.97AB38F80EC5E23A.6E8E564410BE3D60@library-proxy.airnews.net>
Hi all,

I have a question about #'update-instance-for-redefined-class when the class
is redefined more than once.

From what I understand from the hyperspec, the update process is done late
when the object is used. So far so good, but what if the class has changed
more than one time before accessing an object? The
update-instance-for-redefined-class function is called only once.

For instance I have a class with a b c slots.
Then I change it so that I don't have those slots anymore.
all the objects of that class I remove have those slots removed.
I then change the class to put back those a b c slots.
Now the objects that have been accessed previously have lost those slots but
not the other objects.

So my question is : Do I have to write my own update-instance stuff if I
want to cope with this or did I missed some points?

Thank for your ideas on this.

Marc Battyani


PS : Below is a sample I create 2 objects of one class, change this class,
access the first object, change the class again and access both objects.

CL-USER 29 > (defclass class-a ()
    (a b c))

#<STANDARD-CLASS CLASS-A 20EF49C4>

CL-USER 30 > (defmethod update-instance-for-redefined-class :after
    ((a class-a) added deleted plist &key)
(format t "update-instance : ~S ~S ~S ~S~%" a added deleted plist))
#<STANDARD-METHOD UPDATE-INSTANCE-FOR-REDEFINED-CLASS (:AFTER) (CLASS-A T T
T) 203FE3AC>

CL-USER 31 > (setf a (make-instance 'class-a))
#<CLASS-A 2041480C>

CL-USER 32 > (setf aa (make-instance 'class-a))
#<CLASS-A 204030F4>

CL-USER 33 > (defclass class-a ()
    (d e f))

#<STANDARD-CLASS CLASS-A 20EF49C4>

CL-USER 34 > a
update-instance : #<CLASS-A 2041480C> (F E D) (C B A) NIL
#<CLASS-A 2041480C>

CL-USER 35 > (defclass class-a ()
    (a b c))
#<STANDARD-CLASS CLASS-A 20EF49C4>

CL-USER 36 > a
update-instance : #<CLASS-A 2041480C> (C B A) (F E D) NIL
#<CLASS-A 2041480C>

CL-USER 37 > aa
update-instance : #<CLASS-A 204030F4> NIL NIL NIL
#<CLASS-A 204030F4>

CL-USER 38 >

From: Tim Bradshaw
Subject: Re: MOP and update-instance-for-redefined-class
Date: 
Message-ID: <ey367cn3mfa.fsf@haystack.aiai.ed.ac.uk>
* Marc Battyani wrote:

> From what I understand from the hyperspec, the update process is done late
> when the object is used. So far so good, but what if the class has changed
> more than one time before accessing an object? The
> update-instance-for-redefined-class function is called only once.

I don't know what should happen in this case.  It seems like the right
thing to me that all the updates should happen, so if you have
redefined the class twice, then the instance should get updated twice.

But you can call MAKE-INSTANCES-OBSOLETE at some point and, I *think*,
that will cause UPDATE-INSTANCE-FOR-REDEFINED-CLASS to be called on
all the instances that exist at that point.

--tim
From: Marc Battyani
Subject: Re: MOP and update-instance-for-redefined-class
Date: 
Message-ID: <F38174715DCCA6C3.355F8804206C3BA8.2F29E4236B664E1E@library-proxy.airnews.net>
Tim Bradshaw wrote in message ...
>* Marc Battyani wrote:
>
>> From what I understand from the hyperspec, the update process is done
late
>> when the object is used. So far so good, but what if the class has
changed
>> more than one time before accessing an object? The
>> update-instance-for-redefined-class function is called only once.
>
>I don't know what should happen in this case.  It seems like the right
>thing to me that all the updates should happen, so if you have
>redefined the class twice, then the instance should get updated twice.
>
>But you can call MAKE-INSTANCES-OBSOLETE at some point and, I *think*,
>that will cause UPDATE-INSTANCE-FOR-REDEFINED-CLASS to be called on
>all the instances that exist at that point.


I tough this too, but the HyperSpec states that MAKE-INSTANCES-OBSOLETE is
called by defclass if the slots or slots order changes. It inform CLOS that
instances are to be upgraded but not when.

Marc Battyani
From: Thomas A. Russ
Subject: Re: MOP and update-instance-for-redefined-class
Date: 
Message-ID: <ymiemrb78f6.fsf@sevak.isi.edu>
"Marc Battyani" <·············@csi.com> writes:

> For instance I have a class with a b c slots.
> Then I change it so that I don't have those slots anymore.
> all the objects of that class I remove have those slots removed.
> I then change the class to put back those a b c slots.
> Now the objects that have been accessed previously have lost those slots but
> not the other objects.

I would imagine that in most cases this would not really be a problem,
but I suppose in certain circumstances it could bite you.

It does, however, identify an underlying assumption that any changes
to the classes are invertible.

As in your example:  If you change a class with slots a b c to one with
slots d e f, and then change it back to having slots a b c, there seems
to be an assumption that any original instances haven't really been
changed at all, and therefore you get a call to
update-instance-for-redefined-class with no slot changes noted.

This does present a potential problem for serial changes to class
definitions, since the update-instance-for-redefined-class will now have
to be able to handle the transformation from any previous definition to
the new definition.  Unless there is some generic way of handling the
definition changes, this would seem to mean that you would need to
rewrite the update-instance-for-redefined-class method each time you
wanted to change the class definition.

It is my guess that this was an operation that wasn't felt to be one
that would be used very often, so that making the process a bit
laborious would not be unreasonable.  The lazy nature of the update is
probably due to a desire not to force implementations to have a way of
locating every instance of a particular class, since that would also
require there to be something like weak pointers in the implementation
-- or else no instances could ever be garbage-collected.

FWIW, I not too long ago ended up writing some methods for
update-instance-for-redefined-class for use in our LOOM KR language, but
the transformations that I did in that were fairly generic, so it didn't
really matter to my function whether it was called after a single
redefinition or a whole chain of them.

Still it is important to raise the issue so that programmers don't
assume that they will only have to deal with a single change.


-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu