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)))
=> "printing number 2"
As fields in the class are added (at run time) I'd be able to define methods that are connected with the instance of the object. If you were to create a new instance of the class it would have a whole new list of objects with a whole new list of methods.