; http://lispy.wordpress.com/2007/07/09/closures-hash-tables-as-much-oop-as-youll-ever-need/ ; for a more complete oo-in-lisp, see ; http://lib.store.yahoo.net/lib/paulgraham/acl2.lisp ; (search in that file for "parents" (defun create-obi () (let ((h (make-hash-table))) (lambda (command field &optional value) (case command (get (gethash field h)) (set (setf (gethash field h) value)) (run (apply (gethash field h) value)))))) (defun ~ (obi field) (funcall obi 'get field)) (defun ~> (obi field value) (funcall obi 'set field value)) (defun ~! (obi field arguments) (funcall obi 'run field arguments)) #| ; SLIME: The Superior Lisp Interaction Mode for Emacs CL-USER> (setf f (create-obi)) # CL-USER> (~> f 'color 'red) RED CL-USER> (~> f 'shape 'square) SQUARE CL-USER> (~ f 'color) RED T CL-USER> (~ f 'shape) SQUARE T CL-USER> (~> f 'add #'+) # CL-USER> (~! f 'add '(1 2 3 4 5 6 7)) 28 |#