Lisp HUG Maillist Archive

:optimize-slot-access

Hi again,

Setting :optimize-slot-access to nil doesn't do what is suggested by 
the documentation in the case of generic function classes. Here is an 
illustration of what I mean:

(defclass my-generic-function
           (standard-generic-function)
   ((some-slot :accessor some-slot :initform nil))
   (:metaclass funcallable-standard-class))

(defmethod initialize-instance
            ((gf my-generic-function)
             &rest args)
   (apply #'call-next-method
          gf :otimize-slot-access nil
          args))

(defmethod slot-value-using-class
            ((class t)
             (gf my-generic-function)
             (name (eql 'some-slot)))
   "test")

(defgeneric ftest (x)
   (:generic-function-class my-generic-function))

Calling (some-slot #'ftest) yields nil, although it should yield "test" 
IMHO.


Pascal

--
ECOOP 2004 Workshops - Oslo, Norway:
*1st European Lisp and Scheme Workshop, June 13*
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
*2nd Post-Java Workshop, June 14*
http://prog.vub.ac.be/~wdmeuter/PostJava04/


Re: :optimize-slot-access

Pascal Costanza wrote:
Hi again,

Setting :optimize-slot-access to nil doesn't do what is suggested by the documentation in the case of generic function classes. Here is an illustration of what I mean:

(defclass my-generic-function
          (standard-generic-function)
  ((some-slot :accessor some-slot :initform nil))
  (:metaclass funcallable-standard-class))

(defmethod initialize-instance
           ((gf my-generic-function)
            &rest args)
  (apply #'call-next-method
         gf :otimize-slot-access nil
         args))

(defmethod slot-value-using-class
           ((class t)
            (gf my-generic-function)
            (name (eql 'some-slot)))
  "test")

(defgeneric ftest (x)
  (:generic-function-class my-generic-function))

Calling (some-slot #'ftest) yields nil, although it should yield "test" IMHO.


Pascal

--
ECOOP 2004 Workshops - Oslo, Norway:
*1st European Lisp and Scheme Workshop, June 13*
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
*2nd Post-Java Workshop, June 14*
http://prog.vub.ac.be/~wdmeuter/PostJava04/


I notice that you write :otimize-slot-access not :optimize-slot-access, but changing the spelling does not change the returned value in LWW 4.3.6.

I was investigating a similar issue early this week. with an example found in AMOP:

    (defclass monitored-class (standard-class)
      ())
    (defmethod slot-value-using-class :before ((class monitored-class) instance slot-name)
      (note-operation instance slot-name 'slot-value))
    (defmethod (setf slot-value-using-class) :before ((class monitored-class) instance slot-name)
      (note-operation instance slot-name 'set-slot-value))
    (defmethod slot-boundp-using-class :before ((class monitored-class) instance slot-name)
      (note-operation instance slot-name 'slot-makunbound))
    ;;
    (let (history-list)
      (defun note-operation (instance slot-name operation)
        (push (list operation instance slot-name) history-list))
      (defun reset-slot-access-history ()
        (setf history-list '()))
      (defun slot-access-history ()
        (reverse history-list)))
    ;;
    (defclass foo ()
      ((slot1 :accessor foo-slot1 :initarg :slot1)
       (slot2 :accessor foo-slot2 :initarg :slot2))
      (:metaclass monitored-class)
      (:optimize-slot-access nil))
    ;;
    (progn
      (setf f (make-instance 'foo :slot1 100))
      (setf (foo-slot1 f) '300)
      (slot-access-history))

   
where the final form above similarly - an unexpectly - returns NIL.

-Klaus.

Re: :optimize-slot-access

> You have probably just forgotten to use the 'clos package - all the 
> MOP definitions are defined there. I have checked your code, and it 
> works afterwards (except for a few minor bugs in your code, like 
> having the wrong lambda list for (setf slot-value-using-class)).
>
>
> Pascal
>
Duh!  Thanks a lot.  Works for me too --- now.

-Klaus.


Re: :optimize-slot-access

Unable to parse email body. Email id is 2339

Updated at: 2020-12-10 08:56 UTC