Re: A MOP minimisation question
"Pascal Bourguignon (as informatimago at gmail dot com)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
1- using symbol-plist (get and (setf get) are perfectly good options. They seem deprecated because there are more sophisticated mechanisms provided nowadays in Common Lisp, but this old mechanism is simple, efficient, cheap, and works well (thanks to packages to avoid name collisions in keys). 2- using the MOP to define classes with additional slots is nice and clean and easy from conceptually (when you know some OOP). Notably if you have several such classes, and if you integrate it with other MOP mechanisms (for example, update-instance-for-different-class update-instance-for-redefined-class, etc), it may be worthwhile. But again, it’s rare to use the MOP to such an extend. Even in day-to-day CL programming, we use initialize-instance instead of considering shared-initialize (and what about reinitialize-instance?)! So, yes, my advice would be to go on with get and (setf get) unless you’re prepared to make a more intensive and exhaustive use of the MOP. And yes, classes can be nameless: cl-user> (setf (find-class 'foo) (make-instance 'standard-class)) #<standard-class nil> cl-user> (class-name (find-class 'foo)) nil You probably don’t want to do that, but it’s possible if you need to create dynamically more or less temporary classes or for some other reason. -- __Pascal Bourguignon__ [email protected] > On 11 Mar 2026, at 12:05, Tim Bradshaw (as tfb at cley dot com) <[email protected]> wrote: > > As I mentioned in other messages a while ago, I wrote a trivial/special-purpose thing which does a limited version of SoA. I'm now slowly writing a more general one which is inevitably suffering from serious second-system syndrome. > > One of the things it needs to do is maintain information at the class level: things like the layout of the arrays and how slots map onto them, and so on. > > Now bear in mind that once, long ago, I was fairly knowledgeable about the AMOP MOP, but for at least a decade I've barely used CLOS at all (I think I've had the classic 'object systems aren't all that' moment). > > What I do now is to have a metaclass which has some extra slots and so on. > > But an earlier version didn't do that: it just stored the class-level data in properties on the class name. > > If we assume that classes always have names (which is a restriction I am more than happy with) is there really *any* good reason not to do this and thus rely less on MOP features (I still need some small ones). Performance is not a good reason: these things are never used when that matters since their entire purpose is to enable the system to compile things away. > > I realise this is an ideological question: assume I would rather minimise my code's exposure to the MOP even if using it is The Right Thing. > > --tim > > _______________________________________________ > Lisp Hug - the mailing list for LispWorks users > [email protected] > http://www.lispworks.com/support/lisp-hug.html