Michael Weber | 1 Dec 2005 11:22

Redefining classes

Hi,

this mailing list was the closest (hah!) I could find to a (still
active) MOP discussion list.  If my question is off-topic, I'd love
to hear where else to go.

I seem not to understand some aspects of class redefinition.  Suppose
the following situation:

(defclass foo ()
  (...)
  (:metaclass foo-metaclass))

(defclass foo-1 (foo)
  (...)
  (:metaclass foo-metaclass))

If I redefine FOO later on to add or remove slots, it gets
reinitialized, and I have

(defmethod shared-initialize :after ((class foo-metaclass) slot-names 
	                             &rest initargs 
                                     &key &allow-other-keys)
 ...)

which recalculates some slot-based information for FOO then.

However, FOO-1 is left unchanged, which surprised me a little.  I
would have expected that it gets reinitialized as well, thus giving
the above initializer a chance to recalculate information for FOO-1,
(Continue reading)

Pascal Costanza | 1 Dec 2005 17:21

Re: Redefining classes

Hi Michael,

On 1 Dec 2005, at 11:22, Michael Weber wrote:

> Hi,
>
> this mailing list was the closest (hah!) I could find to a (still
> active) MOP discussion list.  If my question is off-topic, I'd love
> to hear where else to go.

The newsgroup comp.lang.lisp would also be appropriate, although your  
question is certainly on-topic here as well. After all, it's a  
question whose answer will clarify how to interpret the CLOS MOP  
specification.

> I seem not to understand some aspects of class redefinition.  Suppose
> the following situation:
>
> (defclass foo ()
>   (...)
>   (:metaclass foo-metaclass))
>
> (defclass foo-1 (foo)
>   (...)
>   (:metaclass foo-metaclass))
>
> If I redefine FOO later on to add or remove slots, it gets
> reinitialized, and I have
>
> (defmethod shared-initialize :after ((class foo-metaclass) slot-names
(Continue reading)

Michael Weber | 1 Dec 2005 20:27

Re: Redefining classes

* Pascal Costanza <pc <at> p-cos.net> [2005-12-01T17:21+0100]:
> On 1 Dec 2005, at 11:22, Michael Weber wrote:
[...]

Thanks for the quick answer, Pascal.  I am trying to wrap my head
around this now.  I might sound a little confusing, as I am not yet
using the right terminology in all cases.  I'll try to fix that. :)

> >Is there a way to invalidate and reinitialize all subclasses?  I would
> >assume that that's a common issue.
> 
> I don't think there's a need to do that. Or do you have evidence that  
> something's going wrong here? If so, could you be more specific -  
> including which Common Lisp implementation you use?

	CL-USER> (list (lisp-implementation-type) (lisp-implementation-version))
	("SBCL" "0.8.16")

It's old, I know.  Various reason hold me off to upgrade it.  If there
have been relevant bug fixes affecting the code below, I'll apologize
for wasting everybody's time.  I'd have to suspend this experiment
then until I can upgrade.

> Maybe it's a good idea to tell us your overall goal - what is it that  
> you are actually trying to achieve?

Automatically generating equality methods for objects (EQL-OBJECTS,
with EQUALS being the user interface).  Code attached.  It's quite
rough around the edges, as I am just writing this.  Notice that I am
generating code for all (CLASS-SLOTS class), which returns a list of
(Continue reading)

Pascal Costanza | 1 Dec 2005 21:43

Re: Redefining classes

Hi Michael,

On 1 Dec 2005, at 20:27, Michael Weber wrote:

> * Pascal Costanza <pc <at> p-cos.net> [2005-12-01T17:21+0100]:
>> On 1 Dec 2005, at 11:22, Michael Weber wrote:
> [...]
>
> Thanks for the quick answer, Pascal.  I am trying to wrap my head
> around this now.  I might sound a little confusing, as I am not yet
> using the right terminology in all cases.  I'll try to fix that. :)

No problem. ;)

>>> Is there a way to invalidate and reinitialize all subclasses?  I  
>>> would
>>> assume that that's a common issue.
>>
>> I don't think there's a need to do that. Or do you have evidence that
>> something's going wrong here? If so, could you be more specific -
>> including which Common Lisp implementation you use?
>
> 	CL-USER> (list (lisp-implementation-type) (lisp-implementation- 
> version))
> 	("SBCL" "0.8.16")
>
> It's old, I know.  Various reason hold me off to upgrade it.  If there
> have been relevant bug fixes affecting the code below, I'll apologize
> for wasting everybody's time.  I'd have to suspend this experiment
> then until I can upgrade.
(Continue reading)

Pascal Costanza | 1 Dec 2005 22:07

Re: Redefining classes


On 1 Dec 2005, at 20:27, Michael Weber wrote:

> However, it is surprising to me that there seems to be no protocol
> available to reinitialize subclasses if a class changes (Issue #2), so
> that EQL-OBJECTS for BAR-1 would be regenerated with up-to-date
> information about class slots of its superclasses.

I have checked the MOP specification, and indeed it seems to be  
lacking in this regard. There should be a specification about when  
finalize-inheritance is called again, whether an implementation can  
choose to delay re-finalization, what class-finalized-p should  
indicate, and so on, but this is all missing (unless I am seriously  
missing something important).

But here is another idea: if your methods should depend on the  
effective rather than the direct slots, you could as well generate  
them in an :after method on compute-effective-slot-definition. That  
one should be called when the direct slot definitions of superclasses  
change...

I hope this helps...

Pascal

--

-- 
Pascal Costanza, mailto:pc <at> p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium
(Continue reading)

JoeSB COE9 | 20 Dec 2005 10:18
Picon

ContextL: Class not intialize

Hi,

I tried to follow ContextL overview document and got stuck.
Here is a part of example that got the error.

;;---------- ctx2.lisp
(defpackage :ctx2
  (:use :contextl))

(in-package :ctx2)

(define-layered-class person ()
  ((name :initarg :name :accessor person-name)))

(deflayer employment-layer)

(define-layered-class person
    :in-layer employment-layer ()
    ((employer :initarg :employer :layered-accessor person-employer)))
;;---------- END ctx2.lisp

And the REPL session goes like this

CL-USER> (compile-file "ctx2.lisp")
;; Compiling file D:\dev\code\lisp-systems\joe\ctx2.lisp ...
;; Wrote file D:\dev\code\lisp-systems\joe\ctx2.fas
0 errors, 0 warnings
#P"D:\\dev\\code\\lisp-systems\\joe\\ctx2.fas"
NIL
NIL
(Continue reading)

Pascal Costanza | 20 Dec 2005 11:52

Re: ContextL: Class not intialize

Hi Joe,

Thanks a lot for reporting this - it's a bug in ContextL. I have  
fixed it in the darcs repository.

If you don't have darcs access, just change the following method in  
cx-special-class.lisp:

(defmethod reinitialize-instance :before
   ((class special-class) &key)
   (when (class-finalized-p class)
     (setf (slot-value class 'old-slot-definitions)
           (class-slots class))))

The bug was that class-slots throws the error you reported when the  
class is not finalized. Fortunately, the code that depends on old- 
slot-definitions doesn't need to run when the class isn't finalized yet.

I hope this helps,
Pascal

On 20 Dec 2005, at 10:18, JoeSB COE9 wrote:

> Hi,
>
> I tried to follow ContextL overview document and got stuck.
> Here is a part of example that got the error.
>
> ;;---------- ctx2.lisp
> (defpackage :ctx2
(Continue reading)


Gmane