Thoughts and tempering expectations on redefining structs

Certainly don’t know all details of the Common Lisp object system (CLOS) and its meta object protocol (MOP), but will try to answer to the best of my knowledge:

Yes, as the class has changed all references to it are now to the new class. This includes method specializations as well.

The meta-object protocol has several methods that can be extended by the user to customize the behaviour. The default method will drop obsolete slots – the CLOS name for fields indeed – and populate new ones from their initial value – if none was defined in the new class, the slot will stay unbound.
If the new values cannot be computed there are several options: First, just leave them unbound, i.e., without a value as an undefined variable, and set them later on each instance if needed, e.g., using an error handler, or, secondly, define a method for update-instance-for-different-class or update-instance-for-redefined-class possible using external/global state to pass in additional information – CL has dynamic variables after all.

Correct, classes are less efficient than structs in Common Lisp. Reasons are that methods are dynamically dispatched at runtime (CL does not devirtualize method calls like Julia, CLOS usually does cache its dispatch table though) and specific methods from the MOP allow the user to hook into this process. Don’t think that all of that would be required to support replacement, but it certainly helps. In contrast to Julia, CL tends to lean towards dynamicism over performance when deciding on its trade-offs.

3 Likes