3 ms·
I think you might have misinterpreted that paragraph somehow? It's not saying that updating all the reference to point to the old object would have the wrong ef
by jsnell 11y ago
I think you might have misinterpreted that paragraph somehow? It's not saying that updating all the reference to point to the old object would have the wrong effect. It's saying that updating the references might not be feasible. A garbage collector has more access than an application programmer...
There is an interesting exception to that in Smalltalk, where the become: operation will replace all references to one object with references to another.
- kazinator 11y agoIt 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).
- dragonwriter 11y ago> A garbage collector has more access than an application programmer... That's generally true, although there's no reason it has to be: a runtime could provide an API giving the application programmer equivalent access. It would probably constitute a giant foot-gun, though.