* lisp/emacs-lisp/gv.el (gv-ref, gv-deref): New function and macro.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 8 Nov 2012 13:34:06 +0000 (08:34 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 8 Nov 2012 13:34:06 +0000 (08:34 -0500)
lisp/ChangeLog
lisp/emacs-lisp/gv.el

index 7c51b13..e0ff05a 100644 (file)
@@ -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):
index d6c9153..34e29ba 100644 (file)
@@ -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)