I want to create a class (lets call it foo) that has a method that allows you to create a method using a passed in name, and object to manipulate contained in the instance of the class. For example:
Code: Select all
(defclass foo ()
((objects :initform '() :accessor list-objects)))
(defparameter inst-1 (make-instance 'foo))
(defparameter inst-2 (make-instance 'foo))
(defparameter x 1)
(defparameter y 2)
(add-method-to-foo inst-1 'print-number x (lambda (z) (print z)))
(add-method-to-foo inst-2 'print-number y (lambda (z) (format t "printing number ~d~%" z)))
(print-number inst-1)
=> 1
(print-number inst-2)
=> "printing number 2"
(list-objects inst-1)
=> (x)
(list-objects inst-2)
=> (y)