20 ms·
It says clearly "change the class rather than X". So X is not the same changing the class, right? Traversing the heap and actually replacing references could a
by kazinator 11y ago
It says clearly "change the class rather than X". So X is not the same changing the class, right?
Traversing the heap and actually replacing references could actually be a good trade-off. It means that class objects don't need to be implemented as handles which point to the real implementation, just in case someone uses change-class. It depends on how often change-class is done.
change-class could tie in to a generational garbage collector. If change-class is done on a baby object, we know that the tenured objects do not point backward to that object, so we don't have to traverse them. Only other baby objects (and of course areas like stack frames and registers).
- jsnell 11y agoRight. The two things are different despite having the same ultimate effect, since (in the context of Common Lisp) one is a generic operation provided by the language, while the other is application-specific with no language support and would need a fragile bespoke implementation for every single use. If the discussion was about Smalltalk that provides become: but not CHANGE-CLASS, it'd be a different question.
- ScottBurson 11y agoCLOS class instances are implemented with handles for a very important reason: so slots can be added to classes dynamically, even if live instances exist. In decades of Common Lisp programming I think I've written a CHANGE-CLASS call maybe twice, but I add slots to classes all the time (and occasionally remove them).