In CLOS, instance remorphing considered useless in practice?
pc at p-cos.net
Wed Dec 9 01:02:10 UTC 2020
> On 7 Dec 2020, at 05:52, Jean-Claude Beaudoin <jean.claude.beaudoin at gmail.com> wrote:
> Hello Pros of Common Lisp,
> Here is my attempt at starting a significant (and hopefully useful) debate on a subject squarely about Common Lisp and its internals.
> My main stance here is to state that I have yet to see, in a significant application, any use of functions #'cl:make-instance-obsolete and #'cl:update-instance-for-redefined-class and of the underlying machinery that support the remorphing of instances following a class redefinition (through a subsequent cl:defclass most likely). I can state the same thing about #'cl:update-instance-for-different-class and #'cl:change-class.
> The machinery required of any CL implementation to properly support those functions (mentioned here above) is quite significant in its complexity and usually imposes a sizeable performance penalty on the speed of any instance slot access.
> A different choice of class redefinition semantics can lead to an implementation of CLOS with much reduced instance slot access overhead.
> The necessity of supporting instance remorphing should therefore be well motivated by very significant gains in application code performance (in speed and/or size and/or expressiveness power).
> Can anyone of you point me to some evidence of such application level usefulness?
> Is there any notorious usecase of this (instance remorphing) since its inclusion into ANSI CL?
The implementation of ContextL relies heavily on the CLOS MOP, and among other things on runtime class redefinition and corresponding updates of class instances. You can find the details how the class redefinition machinery is used in cx-partial-class.lisp at https://github.com/pcostanza/contextl <https://github.com/pcostanza/contextl>
To the best of my knowledge, ContextL is one of the most efficient implementations of context-oriented programming (as compared to other implementations of COP for Java, Smalltalk, and a few other languages). This is because there is enough machinery in the CLOS MOP that provides the necessary dynamism and efficiency at the same time.
ContextL has been used in production, so should count as relevant.
Removal of features can lead to more efficient implementation strategies, but also leads to less expressivity. It’s always difficult to draw a good line between what is good for most cases, and what is necessary for some. I, for one, am happy that CLOS MOP provides this amount of flexibility. There are enough OOP systems / languages with reduced expressivity (including ISLISP, Dylan, and some Scheme implementations) that we don’t necessarily need another one.
It has already been pointed out in this thread that you can always revert to the much more restricted defstruct. Maybe that one is too restrictive for your taste, but again, it is difficult to draw a good line between restrictive and expressive, and no compromise will make everybody happy.
I think CLOS could be even more flexible, without loss of efficiency, but that’s a different discussion.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pro