Re: MOP question for language lawyers: can you specialize on standard-class

"Willem Broekema (as metawilm at gmail dot com)" <[email protected]> Wed, 22 Apr 2026 09:34:02 +0200
Newsgroups gmane.lisp.lispworks.general
Message-ID <CAHP7kS-ROAzVQ8UtRB-SzT_wEqtOrZVMRut+m=AKLZQ_TuvBgg@mail.gmail.com>
Your question of what's allowed, reminded me of the MOP  "Restrictions
on Portable Programs" section
(https://www.lispworks.com/documentation/lw70/MOP/mop/concepts.html):

  Portable programs must not redefine any specified classes, generic
functions, methods or method combinations. Any method defined by a
portable program on a specified generic function must have at least
one specializer that is neither a specified class nor an eql
specializer whose associated value is an instance of a specified
class.

If the slot name is fixed and it's a simple lookup of a real slot, you
can use #'slot-definition-location and #'standard-instance-access to
bypass the lookup machinery. See e.g.
https://github.com/metawilm/cl-python/blob/master/runtime/dictattr.lisp

- Willem

On Wed, Apr 22, 2026 at 8:06 AM Tim Bradshaw (as tfb at cley dot com)
<[email protected]> wrote:
>
> Incidentally, as best I can tell there can be huge variations in slot access performance for standard instances depending on the phase of the moon.  LW is always good (cf SBCL) but sometimes it's much, much better than others.  I'm measuring a large number of (incf (the fixnum (slot-value x 'a)))s for a class with a single slot, so a read followed by a write.  Things seem to, sometimes, get much better on recompilation.
>
> It may be this is some artifact of my measurement: I need to try to rule that out.
>
> --tim
>
> > On 21 Apr 2026, at 18:41, Tim Bradshaw (as tfb at tfeb dot org) <[email protected]> wrote:
> >
> > On 21 Apr 2026, at 18:09, Martin Simmons <[email protected]> wrote:
> >>
> >> Yes, I don't see why not.  In fact, I think you have to specialize on the
> >> class argument if you don't have a specific metaclass because otherwise the
> >> AMOP method that specializes on standard-class (and doesn't specialize on
> >> object) will be the most applicable method and your method will never be
> >> called.
> >
> > Yes, I think you have to specialize on the class as you say.  I was wondering if you were required to define a subclass of standard-class rather than standard-class itself to specialize on.
> >
> >> What are your concerns about it?
> >
> > I think that if you were required to subclass standard-class, then implementations could know that, for objects whose metaclass was standard-class, it is safe to short-circuit slot access (I know LW has an approach to this).
> >
> > I don't think that's a very good situation (although it's better than 'all bets are off'), because it puts you in what I think of as the scripting-language situation, where things whose metaclass is standard-class can be really quick, but the moment you define your own metaclass, nothing can ever be that quick.  So in that sense LW's answer is better.
> >
> > --tim
> >
> > _______________________________________________
> > Lisp Hug - the mailing list for LispWorks users
> > [email protected]
> > http://www.lispworks.com/support/lisp-hug.html
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> [email protected]
> http://www.lispworks.com/support/lisp-hug.html

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html