Skip to content

Instantly share code, notes, and snippets.

@PuercoPop
Created August 8, 2013 15:02
Show Gist options
  • Save PuercoPop/6185388 to your computer and use it in GitHub Desktop.
Save PuercoPop/6185388 to your computer and use it in GitHub Desktop.
Abhorrent Interface implementation
(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