diff options
| author | Glenn Morris | 2012-11-07 00:28:34 -0800 |
|---|---|---|
| committer | Glenn Morris | 2012-11-07 00:28:34 -0800 |
| commit | 940eac6d18123bb61b34e6f940d4f3ddfb0c0cab (patch) | |
| tree | ddba04445d2d1e380b8a4e2e390672c4aff1417d | |
| parent | cce0aa5aac8ae6a7fbcf1e586ab5db1cb836e26a (diff) | |
| download | emacs-940eac6d18123bb61b34e6f940d4f3ddfb0c0cab.tar.gz emacs-940eac6d18123bb61b34e6f940d4f3ddfb0c0cab.zip | |
* cl.texi (Obsolete Setf Customization): Give define-modify-macro replacement.
| -rw-r--r-- | doc/misc/ChangeLog | 1 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 45 |
2 files changed, 35 insertions, 11 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 49f86ef093b..93a2971f8c6 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | * cl.texi (Obsolete Setf Customization): | 3 | * cl.texi (Obsolete Setf Customization): |
| 4 | Revert defsetf example to the more correct let rather than prog1. | 4 | Revert defsetf example to the more correct let rather than prog1. |
| 5 | Give define-modify-macro gv.el replacement. | ||
| 5 | 6 | ||
| 6 | 2012-11-06 Glenn Morris <rgm@gnu.org> | 7 | 2012-11-06 Glenn Morris <rgm@gnu.org> |
| 7 | 8 | ||
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index e39186c1222..21750b79c93 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -4905,15 +4905,17 @@ Common Lisp defines three macros, @code{define-modify-macro}, | |||
| 4905 | @code{defsetf}, and @code{define-setf-method}, that allow the | 4905 | @code{defsetf}, and @code{define-setf-method}, that allow the |
| 4906 | user to extend generalized variables in various ways. | 4906 | user to extend generalized variables in various ways. |
| 4907 | In Emacs, these are obsolete, replaced by various features of | 4907 | In Emacs, these are obsolete, replaced by various features of |
| 4908 | @file{gv.el} in Emacs 24.3. Many of the implementation | 4908 | @file{gv.el} in Emacs 24.3. |
| 4909 | details in the following are out-of-date. | 4909 | @xref{Adding Generalized Variables,,,elisp,GNU Emacs Lisp Reference Manual}. |
| 4910 | @c FIXME this whole section needs updating. | 4910 | |
| 4911 | 4911 | ||
| 4912 | @defmac define-modify-macro name arglist function [doc-string] | 4912 | @defmac define-modify-macro name arglist function [doc-string] |
| 4913 | This macro defines a ``read-modify-write'' macro similar to | 4913 | This macro defines a ``read-modify-write'' macro similar to |
| 4914 | @code{cl-incf} and @code{cl-decf}. The macro @var{name} is defined | 4914 | @code{cl-incf} and @code{cl-decf}. You can replace this macro |
| 4915 | to take a @var{place} argument followed by additional arguments | 4915 | with @code{gv-letplace}. |
| 4916 | described by @var{arglist}. The call | 4916 | |
| 4917 | The macro @var{name} is defined to take a @var{place} argument | ||
| 4918 | followed by additional arguments described by @var{arglist}. The call | ||
| 4917 | 4919 | ||
| 4918 | @example | 4920 | @example |
| 4919 | (@var{name} @var{place} @var{args}@dots{}) | 4921 | (@var{name} @var{place} @var{args}@dots{}) |
| @@ -4936,8 +4938,8 @@ which in turn is roughly equivalent to | |||
| 4936 | For example: | 4938 | For example: |
| 4937 | 4939 | ||
| 4938 | @example | 4940 | @example |
| 4939 | (define-modify-macro cl-incf (&optional (n 1)) +) | 4941 | (define-modify-macro incf (&optional (n 1)) +) |
| 4940 | (define-modify-macro cl-concatf (&rest args) concat) | 4942 | (define-modify-macro concatf (&rest args) concat) |
| 4941 | @end example | 4943 | @end example |
| 4942 | 4944 | ||
| 4943 | Note that @code{&key} is not allowed in @var{arglist}, but | 4945 | Note that @code{&key} is not allowed in @var{arglist}, but |
| @@ -4947,14 +4949,28 @@ Most of the modify macros defined by Common Lisp do not exactly | |||
| 4947 | follow the pattern of @code{define-modify-macro}. For example, | 4949 | follow the pattern of @code{define-modify-macro}. For example, |
| 4948 | @code{push} takes its arguments in the wrong order, and @code{pop} | 4950 | @code{push} takes its arguments in the wrong order, and @code{pop} |
| 4949 | is completely irregular. | 4951 | is completely irregular. |
| 4952 | |||
| 4953 | The above @code{incf} example could be written using | ||
| 4954 | @code{gv-letplace} as: | ||
| 4955 | @example | ||
| 4956 | (defmacro incf (place &optional n) | ||
| 4957 | (gv-letplace (getter setter) place | ||
| 4958 | (macroexp-let2 nil v (or n 1) | ||
| 4959 | (funcall setter `(+ ,v ,getter))))) | ||
| 4960 | @end example | ||
| 4961 | @ignore | ||
| 4962 | (defmacro concatf (place &rest args) | ||
| 4963 | (gv-letplace (getter setter) place | ||
| 4964 | (macroexp-let2 nil v (mapconcat 'identity args "") | ||
| 4965 | (funcall setter `(concat ,getter ,v))))) | ||
| 4966 | @end ignore | ||
| 4950 | @end defmac | 4967 | @end defmac |
| 4951 | 4968 | ||
| 4952 | @defmac defsetf access-fn update-fn | 4969 | @defmac defsetf access-fn update-fn |
| 4953 | This is the simpler of two @code{defsetf} forms, and is | 4970 | This is the simpler of two @code{defsetf} forms, and is |
| 4954 | replaced by @code{gv-define-simple-setter} in Emacs 24.3. | 4971 | replaced by @code{gv-define-simple-setter}. |
| 4955 | @xref{Adding Generalized Variables,,,elisp,GNU Emacs Lisp Reference Manual}. | ||
| 4956 | 4972 | ||
| 4957 | Where @var{access-fn} is the name of a function that accesses a place, | 4973 | With @var{access-fn} the name of a function that accesses a place, |
| 4958 | this declares @var{update-fn} to be the corresponding store function. | 4974 | this declares @var{update-fn} to be the corresponding store function. |
| 4959 | From now on, | 4975 | From now on, |
| 4960 | 4976 | ||
| @@ -4993,6 +5009,13 @@ Some examples are: | |||
| 4993 | (defsetf car setcar) | 5009 | (defsetf car setcar) |
| 4994 | (defsetf buffer-name rename-buffer t) | 5010 | (defsetf buffer-name rename-buffer t) |
| 4995 | @end example | 5011 | @end example |
| 5012 | |||
| 5013 | These translate directly to @code{gv-define-simple-setter}: | ||
| 5014 | |||
| 5015 | @example | ||
| 5016 | (gv-define-simple-setter car setcar) | ||
| 5017 | (gv-define-simple-setter buffer-name rename-buffer t) | ||
| 5018 | @end example | ||
| 4996 | @end defmac | 5019 | @end defmac |
| 4997 | 5020 | ||
| 4998 | @defmac defsetf access-fn arglist (store-var) forms@dots{} | 5021 | @defmac defsetf access-fn arglist (store-var) forms@dots{} |