This code creates an error: The slot COMMON-LISP-USER::NAME is unbound in the object #<THING {1002B830F3}>. I tried sbcl and clisp, both creating same problem. I can initialize instance of ash manually, but when done in "when" statement, it doesn't work
(defclass thing ()
((name :initarg :name :accessor thing-name)
(properties :initform nil :accessor thing-properties)))
(defmethod initialize-instance :around ((obj thing) &rest initargs &key &allow-other-keys)
(let* ((class (class-of obj)))
(apply #'call-next-method obj
(loop for (key val) on initargs by #'cddr
when (member key '(name properties)) ; Explicitly allow these
append (list key val)))))
(defclass process ()
((name :initarg :name :accessor process-name)))
(defmethod burn ((proc process) (chair thing) (oxygen thing))
(declare (ignore proc))
(when (and (string= (thing-name chair) "chair")
(string= (thing-name oxygen) "oxygen"))
(make-instance 'thing :name "ash")))
;; Test
(defparameter *chair* (make-instance 'thing :name "chair"))
(defparameter *oxygen* (make-instance 'thing :name "oxygen"))
(defparameter *burning* (make-instance 'process :name "burning"))
;; Perform the burn operation
(defparameter *result* (burn *burning* *chair* *oxygen*))
;; Debugging output
(format t "Result: ~A" *result*) ; Should show the created "ash" instance if the burn succeeds