MOP: class-level variables, prototypes
"Christopher Stacy (as cstacy at dtpq dot com)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
Over all these years I have rarely needed the MOP. I hope this is not too off-topic; I think most active and aspiring Lisp programmers are on the HUG, and I don't know of a general Lisp discussion mailing list. Today I am using :CLASS allocated slots and have learned something I wanted to pass on. Most documentation seems a little vague on the point, but indeed, you're only going to get the one slot in the final object. Maybe this is obvious, but if you hoped that multiple subclasses could each get their own :class allocated slot from your mixin that mentioned it, no dice. All the subclasses are going to share that one slot. This is what is meant by "class allocated slots cannot be inherited". Of course you inherit the slot, it's that you don't inherit a new slot that will be class allocated. Even though your classes have nothing to do with each other, all will be sharing that very one slot from the superclass. Classes have a prototype which is like the instance, and you can get your hands on it and it will run methods that don't side-effect the (non-existent) instance. It will also have any :class allocated slots, and they will be initialized. So methods can side-effect those. Before these handy tricks will work, the class must be finalized. CLOS is only required to ensure they are finalized when you call make-instance. You can call a MOP function to finalize them when you want, instead. What's all this good for? Say you have a class name (symbol) and want some computation done by the class, but it's too early because it doesn't make sense to make an instance yet. You're probably bootstrapping something or this is a factory and it's not yet time to make even one instance. Whatever, you have all the things you need: a functional prototype with class-level state. I recommend portable MOP. aka the CLOSER-MOP package. _______________________________________________ Lisp Hug - the mailing list for LispWorks users [email protected] http://www.lispworks.com/support/lisp-hug.html