What a way to start a little update on the the object framework that I have been pushing on.
The last update talked about ‘destructuring-bind‘. I had an epipheny the other day when I was trying to tdd a way to create generic functions for the framework. That led me to throwing away the destructuring-bind.
In order to explain my reasoning we need to go back to the representation of an object in the framework. The representation is a list of closures referenced by properties.
(defun hello (obj &rest args) (apply (getf obj :hello) args) (defvar hold1 (list :hello (lambda () (print 'hello)))) (defvar hold2 (list :hello (lambda (x) (print x))))
The above lists can be accessed with a getf that retrieves the lambda from the list. To execute the lambda just apply. The hello defun above will handle either list as obj.
Something that I now know, is that the lambda does its own destructuring-bind on its parameter list. So here is how I create the accessor function for all objects (generic and multiple signatures):
(defmacro make-property (name) (let ((g (gensym))) (multiple-value-bind (sym-name key-name) (symbol-and-keyword name) `(progn (if (not (fboundp ',sym-name)) (defun ,sym-name (obj &rest ,g) (block ,sym-name (apply (getf obj ,key-name) ,g)))))))
Happy New Year!