sasagawa888/eisl

Initform evaluates when defclass, and be shared it's value between instances

Closed this issue · 3 comments

:initform in defclass specification is

"This form is evaluated every time it is used to initialize the slot".

But evaluates when defclass, and be shared it's value between instances.

(defclass <inner> () ((slot-inner :accessor slot-inner :initarg slot-inner)))

(defclass <outer> () ((slot-outer :reader slot-outer :initform (create (class <inner>) 'slot-inner 'hoge))))

(let ((outer-1 (create (class <outer>)))
      (outer-2 (create (class <outer>))))
  (format (standard-output) "~S~%" (slot-inner (slot-outer outer-1)))
  ;; => HOGE
  (format (standard-output) "~S~%" (slot-inner (slot-outer outer-2)))
  ;; => HOGE
  (setf (slot-inner (slot-outer outer-1)) 'FUGA)
  (format (standard-output) "~S~%" (slot-inner (slot-outer outer-1)))
  ;; => FUGA
  (format (standard-output) "~S~%" (slot-inner (slot-outer outer-2)))
  ;; => Expected HOGE, but FUGA
  )

Thank you for the report. I'll review it thoroughly.

It may be an issue with setf. The accessor was not designed to handle nesting.

Fixed.
I've made it so that when an instance is created using create, it now makes a copy of the :initform instance that was defined with defclass. It’s working well in that example. How about in other cases? If any issues arise, please report them.