summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2012-11-08 08:34:06 -0500
committerStefan Monnier <monnier@iro.umontreal.ca>2012-11-08 08:34:06 -0500
commitd14bb752ea51331ce2fb459c6ffacd8b11f80bb0 (patch)
tree268bc5ea61b92967abb8befac626ef8b87c0d230 /lisp
parentc66f21eaf103f9ace7400f3d8a06fc34539efca9 (diff)
downloademacs-d14bb752ea51331ce2fb459c6ffacd8b11f80bb0.tar.gz
emacs-d14bb752ea51331ce2fb459c6ffacd8b11f80bb0.tar.bz2
emacs-d14bb752ea51331ce2fb459c6ffacd8b11f80bb0.zip
* lisp/emacs-lisp/gv.el (gv-ref, gv-deref): New function and macro.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/gv.el18
2 files changed, 22 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7c51b139ec3..e0ff05aa7dc 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2012-11-08 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * emacs-lisp/gv.el (gv-ref, gv-deref): New function and macro.
+
2012-11-07 Michael Albinus <michael.albinus@gmx.de>
* notifications.el (notifications-get-server-information-method):
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index d6c91539a90..34e29ba1cbd 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -433,6 +433,24 @@ The return value is the last VAL in the list.
`(logior (logand ,v ,mask)
(logand ,getter (lognot ,mask))))))))))
+;;; References
+
+;;;###autoload
+(defmacro gv-ref (place)
+ "Return a reference to PLACE.
+This is like the `&' operator of the C language."
+ (gv-letplace (getter setter) place
+ `(cons (lambda () ,getter)
+ (lambda (gv--val) ,(funcall setter 'gv--val)))))
+
+;;;###autoload
+(defsubst gv-deref (ref)
+ "Dereference REF, returning the referenced value.
+This is like the `*' operator of the C language.
+REF must have been previously obtained with `gv-ref'."
+ (declare (gv-setter (lambda (v) `(funcall (cdr ,ref) ,v))))
+ (funcall (car ref)))
+
;;; Vaguely related definitions that should be moved elsewhere.
;; (defun alist-get (key alist)