The less-familiar parts of Lisp for beginners — find-class

Another feature of lisp that the casual new user probably hasn’t encountered is find-class.  This accessor retrieves the class definition of the symbol.  I’ve talked a bit about the class and polymorphism model in Lisp before, see here and here.

As we’ve mentioned throughout this series, a Lisp program is put together somewhat differently than a C++ program.  In Lisp, we start with a Lisp image, and then, by loading forms, we augment the image with definitions of functions and data structures.  So, you might ask, what actually happens when a defclass form is loaded into the image?  Throughout this series I’ve been sticking to C++ nomenclature.  The “class” is the abstract definition that tells the system what is involved in creating objects.  The “object” is a single instance of the class.  But what happens when a defclass form is loaded into a Lisp image?  Well, it creates a new object.  Not an object of the class you’re defining, it creates an object of type standard-class.  That object is tied to a symbol, the name of the class itself.  The make-instance function actually uses find-class or its equivalent to retrieve the object associated with the name of the object your instantiating, and then uses that object to construct the instance.  So, find-class retrieves the object that defines the class, just as fdefinition retrieves the actual function bound to the name passed.

You’re not likely to find very many uses for this accessor.  It can be used in the implementations of defclass and make-instance, and there might be some situations where you want your code to examine a symbol to determine whether it’s a class, a structure, or something else, but these are quite esoteric applications.

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.