Skip to content

Instantly share code, notes, and snippets.

@jorgenschaefer
Created August 23, 2015 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgenschaefer/bd7616151eb698903d07 to your computer and use it in GitHub Desktop.
Save jorgenschaefer/bd7616151eb698903d07 to your computer and use it in GitHub Desktop.
(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