Created
August 23, 2015 09:48
-
-
Save jorgenschaefer/bd7616151eb698903d07 to your computer and use it in GitHub Desktop.
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 ref-define (type-symbol getter setter) | |
(put type-symbol 'ref-getter getter) | |
(put type-symbol 'ref-setter setter)) | |
(defun ref (obj &rest args) | |
(apply (get (type-of obj) 'ref-getter) | |
obj | |
args)) | |
(gv-define-simple-setter | |
ref | |
(lambda (obj &rest args) | |
(apply (get (type-of obj) 'ref-setter) | |
obj | |
args))) | |
(ref-define 'hash-table | |
(lambda (table key &optional default) | |
(gethash key table default)) | |
(lambda (table key value) | |
(puthash key value table))) | |
(ert-deftest ref-hash-tables () | |
(let ((table (make-hash-table))) | |
(setf (ref table 'foo) 'bar) | |
(should (eq (ref table 'foo) | |
'bar)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment