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

"Madhu (as enometh at meer dot net)" <[email protected]> Thu, 07 May 2026 18:17:03 +0530 (IST)
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
* Martin Simmons <[email protected]> :
Wrote on Tue, 21 Apr 2026 18:09:05 +0100:

> 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.
>
> What are your concerns about it?

It doesn't work on all implementations.  SLOT-VALUE doesn't go through
slot-value-using-class in say, ECL and CCL in the following example.

(require 'closer-mop)

(defclass foo ()
  ((slot-1 :initform 10)
   (slot-2 :initform 20))
 #+lispworks(:optimize-slot-access nil))

(defmethod c2mop:slot-value-using-class ((class standard-class) (obj foo) slot)
  (let ((slot-name (etypecase slot
		     (symbol slot)
		     (c2mop:standard-effective-slot-definition
		      (c2mop:slot-definition-name slot)))))
    (cond ((eql slot-name 'slot-2) 42)
	  (t (call-next-method)))))

(setq $f (make-instance 'foo))
(slot-value $f 'slot-2) ; 20 on ecl,ccl,

(c2mop:slot-value-using-class (class-of $f)
			      $f
			      (find 'slot-2
				    (c2mop:class-slots (class-of $f))
				    :key
				    #'c2mop:slot-definition-name)) ;42


Are the implementation justified in ignoring s-v-u-c for standard
slots?  I can't tell.

BTW on another note, if you elide the slot slot-2 from defclass foo,
the code still works in lispworks, but all other implementations throw
a slot-missing error.

If in the future lispworks changes the signature of s-v-u-c to use a
slot-definition object instead of a symbol, will it still be justified
in not throwing a slot-missing error?, ---Regards, Madhu

[Rainer Joswig's answer in
https://stackoverflow.com/questions/17554370/how-to-define-a-structure-in-lisp-with-arbitrary-number-of-args
works only with lw, on account of the slot-missing behaviour]

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