The less-familiar parts of Lisp for beginners — make-instances-obsolete

Our next stop in the Lisp features that newcomers arriving from C++ might not be aware of is make-instances-obsolete.  We’ve touched on this capacity briefly before, in this article.

Once again, this returns to a fundamental difference between C++ programs and Lisp programs, one that I’ve mentioned several times before in this series, but which I will repeat here.

C++ programs are written, compiled, and executed.  Barring implementation-defined tricks like shared object plugins, if the C++ programmer wants to make a change to the code, he edits the source, recompiles it, and then shuts down the running version of the program, and then restarts the program using the changed binary.

In Lisp, functions and data are added to a Lisp instance, and the “program” can be modified by updating functions in the Lisp, without shutting it down and restarting.  One possible change is to modify the definition of a class, which can be done even if there are instances of the class present in the Lisp instance.  When the class is modified in such a way as to change the slots (the equivalent of members in C++ structs or classes), then make-instances-obsolete is automatically invoked on the class, and all instances are marked for updating.  At some implementation-defined time later, but before the next access to a slot in a specific instance, the method update-instance-for-redefined-class is called on the instance to make any required changes to bring an instance constructed in the old definition into compliance with the new definition of its class.  The programmer can also call make-instances-obsolete explicitly, in those cases where the automatic invocation would not be performed because the slots are unchanged.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.