[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master d1d738c: Add some examples in "Adding Generalized V
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master d1d738c: Add some examples in "Adding Generalized Variables" |
Date: |
Fri, 16 Aug 2019 02:59:03 -0400 (EDT) |
branch: master
commit d1d738c8264b3e756259e3ba2112ff96b8ecf829
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Add some examples in "Adding Generalized Variables"
* doc/lispref/variables.texi (Adding Generalized Variables): Add
examples for `gv-define-expander' and `gv-letplace' (bug#13343).
---
doc/lispref/variables.texi | 41 +++++++++++++++++++++++++++++++++++------
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 6e6448e..d62a5aa 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2533,14 +2533,43 @@ set. An example of using this macro is:
@end example
@end defmac
-@findex gv-define-expander
-@findex gv-letplace
-@c FIXME? Not sure what or how much to say about these.
-@c See cl.texi for an example of using gv-letplace.
-For more control over the expansion, see the macro @code{gv-define-expander}.
+@defmac gv-define-expander name handler
+For more control over the expansion, the @code{gv-define-expander}
+macro can be used. For instance, a settable @code{substring} could be
+implemented this way:
+
+@example
+(gv-define-expander substring
+ (lambda (do place from &optional to)
+ (gv-letplace (getter setter) place
+ (macroexp-let2* nil ((start from) (end to))
+ (funcall do `(substring ,getter ,start ,end)
+ (lambda (v)
+ (funcall setter `(cl--set-substring
+ ,getter ,start ,end ,v))))))))
+@end example
+@end defmac
+
+@defmac gv-letplace (getter setter) place &rest body
The macro @code{gv-letplace} can be useful in defining macros that
perform similarly to @code{setf}; for example, the @code{incf} macro
-of Common Lisp. Consult the source file @file{gv.el} for more details.
+of Common Lisp could be implemented this way:
+
+@example
+(defmacro incf (place &optional n)
+ (gv-letplace (getter setter) place
+ (macroexp-let2 nil v (or n 1)
+ (funcall setter `(+ ,v ,getter)))))
+@end example
+
+@var{getter} will be bound to a copyable expression that returns the
+value of @var{place}. @var{setter} will be bound to a function that
+takes an expression @var{v} and returns a new expression that sets
+@var{place} to @var{v}. @var{body} should return a Emacs Lisp
+expression manipulating @var{place} via @var{getter} and @var{setter}.
+@end defmac
+
+Consult the source file @file{gv.el} for more details.
@cindex CL note---no @code{setf} functions
@quotation
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master d1d738c: Add some examples in "Adding Generalized Variables",
Lars Ingebrigtsen <=