Created
August 8, 2013 15:02
-
-
Save PuercoPop/6185388 to your computer and use it in GitHub Desktop.
Abhorrent Interface implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun make-interface (&rest args &key &allow-other-keys) | |
(let ((methods (make-hash-table))) | |
(loop for (name function . rest) on args by #'cddr | |
do | |
(setf (gethash name methods) function)) | |
(lambda (action name &optional value) | |
(ecase action | |
(:get (gethash name methods)) | |
(:set (setf (gethash name methods) value)))))) | |
(let ((my-num | |
(make-interface :add #'+ :sub #'- :identity (lambda (x) x)))) | |
(funcall (funcall my-num :get :add) 1 3)) | |
;; => 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment