diff options
| author | Glenn Morris | 2012-10-28 18:29:22 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-10-28 18:29:22 -0700 |
| commit | d571e9c385d648a90581e2c5cd1a883b8c0ea0e4 (patch) | |
| tree | f99e49b26363c7d865c56a1b0169f565109c4c7b /doc/misc | |
| parent | a3c5b619fc4c1334c4d295def008318ae0e9bca7 (diff) | |
| download | emacs-d571e9c385d648a90581e2c5cd1a883b8c0ea0e4.tar.gz emacs-d571e9c385d648a90581e2c5cd1a883b8c0ea0e4.zip | |
Move some cl.texi setf extensions to the Obsolete appendix
* doc/misc/cl.texi (Customizing Setf):
Move contents to "Obsolete Setf Customization".
(Modify Macros, Multiple Values): Remove mentions of obsolete feature.
Diffstat (limited to 'doc/misc')
| -rw-r--r-- | doc/misc/ChangeLog | 2 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 425 |
2 files changed, 205 insertions, 222 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 9aeaf87426e..e85e18ff5c7 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | * cl.texi (Organization): More details on cl-lib.el versus cl.el. | 3 | * cl.texi (Organization): More details on cl-lib.el versus cl.el. |
| 4 | (Setf Extensions): Remove `apply' setf since it seems to be disabled. | 4 | (Setf Extensions): Remove `apply' setf since it seems to be disabled. |
| 5 | (Customizing Setf): Move contents to "Obsolete Setf Customization". | ||
| 6 | (Modify Macros, Multiple Values): Remove mentions of obsolete feature. | ||
| 5 | 7 | ||
| 6 | 2012-10-28 Glenn Morris <rgm@gnu.org> | 8 | 2012-10-28 Glenn Morris <rgm@gnu.org> |
| 7 | 9 | ||
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index b77dfcd94be..086cc25fbcc 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -883,7 +883,6 @@ generalized variables. | |||
| 883 | @menu | 883 | @menu |
| 884 | * Setf Extensions:: Additional @code{setf} places. | 884 | * Setf Extensions:: Additional @code{setf} places. |
| 885 | * Modify Macros:: @code{cl-incf}, @code{cl-rotatef}, @code{letf}, @code{cl-callf}, etc. | 885 | * Modify Macros:: @code{cl-incf}, @code{cl-rotatef}, @code{letf}, @code{cl-callf}, etc. |
| 886 | * Customizing Setf:: @code{define-modify-macro}, @code{defsetf}, @code{define-setf-method}. | ||
| 887 | @end menu | 886 | @end menu |
| 888 | 887 | ||
| 889 | @node Setf Extensions | 888 | @node Setf Extensions |
| @@ -1198,9 +1197,7 @@ Some more examples: | |||
| 1198 | (cl-callf cl-union happy-people (list joe bob) :test 'same-person) | 1197 | (cl-callf cl-union happy-people (list joe bob) :test 'same-person) |
| 1199 | @end example | 1198 | @end example |
| 1200 | 1199 | ||
| 1201 | @xref{Customizing Setf}, for @code{define-modify-macro}, a way | 1200 | Note again that @code{cl-callf} is an extension to standard Common Lisp. |
| 1202 | to create even more concise notations for modify macros. Note | ||
| 1203 | again that @code{cl-callf} is an extension to standard Common Lisp. | ||
| 1204 | @end defmac | 1201 | @end defmac |
| 1205 | 1202 | ||
| 1206 | @defmac cl-callf2 @var{function} @var{arg1} @var{place} @var{args}@dots{} | 1203 | @defmac cl-callf2 @var{function} @var{arg1} @var{place} @var{args}@dots{} |
| @@ -1216,214 +1213,6 @@ blocks for other macros like @code{cl-incf}, @code{cl-pushnew}, and | |||
| 1216 | macros are used in the processing of symbol macros; | 1213 | macros are used in the processing of symbol macros; |
| 1217 | @pxref{Macro Bindings}. | 1214 | @pxref{Macro Bindings}. |
| 1218 | 1215 | ||
| 1219 | @node Customizing Setf | ||
| 1220 | @subsection Customizing Setf | ||
| 1221 | |||
| 1222 | @noindent | ||
| 1223 | Common Lisp defines three macros, @code{define-modify-macro}, | ||
| 1224 | @code{defsetf}, and @code{define-setf-method}, that allow the | ||
| 1225 | user to extend generalized variables in various ways. | ||
| 1226 | |||
| 1227 | @defmac define-modify-macro name arglist function [doc-string] | ||
| 1228 | This macro defines a ``read-modify-write'' macro similar to | ||
| 1229 | @code{cl-incf} and @code{cl-decf}. The macro @var{name} is defined | ||
| 1230 | to take a @var{place} argument followed by additional arguments | ||
| 1231 | described by @var{arglist}. The call | ||
| 1232 | |||
| 1233 | @example | ||
| 1234 | (@var{name} @var{place} @var{args}...) | ||
| 1235 | @end example | ||
| 1236 | |||
| 1237 | @noindent | ||
| 1238 | will be expanded to | ||
| 1239 | |||
| 1240 | @example | ||
| 1241 | (cl-callf @var{func} @var{place} @var{args}...) | ||
| 1242 | @end example | ||
| 1243 | |||
| 1244 | @noindent | ||
| 1245 | which in turn is roughly equivalent to | ||
| 1246 | |||
| 1247 | @example | ||
| 1248 | (setf @var{place} (@var{func} @var{place} @var{args}...)) | ||
| 1249 | @end example | ||
| 1250 | |||
| 1251 | For example: | ||
| 1252 | |||
| 1253 | @example | ||
| 1254 | (define-modify-macro cl-incf (&optional (n 1)) +) | ||
| 1255 | (define-modify-macro cl-concatf (&rest args) concat) | ||
| 1256 | @end example | ||
| 1257 | |||
| 1258 | Note that @code{&key} is not allowed in @var{arglist}, but | ||
| 1259 | @code{&rest} is sufficient to pass keywords on to the function. | ||
| 1260 | |||
| 1261 | Most of the modify macros defined by Common Lisp do not exactly | ||
| 1262 | follow the pattern of @code{define-modify-macro}. For example, | ||
| 1263 | @code{push} takes its arguments in the wrong order, and @code{pop} | ||
| 1264 | is completely irregular. You can define these macros ``by hand'' | ||
| 1265 | using @code{get-setf-method}, or consult the source | ||
| 1266 | to see how to use the internal @code{setf} building blocks. | ||
| 1267 | @end defmac | ||
| 1268 | |||
| 1269 | @defmac defsetf access-fn update-fn | ||
| 1270 | This is the simpler of two @code{defsetf} forms. Where | ||
| 1271 | @var{access-fn} is the name of a function which accesses a place, | ||
| 1272 | this declares @var{update-fn} to be the corresponding store | ||
| 1273 | function. From now on, | ||
| 1274 | |||
| 1275 | @example | ||
| 1276 | (setf (@var{access-fn} @var{arg1} @var{arg2} @var{arg3}) @var{value}) | ||
| 1277 | @end example | ||
| 1278 | |||
| 1279 | @noindent | ||
| 1280 | will be expanded to | ||
| 1281 | |||
| 1282 | @example | ||
| 1283 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} @var{value}) | ||
| 1284 | @end example | ||
| 1285 | |||
| 1286 | @noindent | ||
| 1287 | The @var{update-fn} is required to be either a true function, or | ||
| 1288 | a macro which evaluates its arguments in a function-like way. Also, | ||
| 1289 | the @var{update-fn} is expected to return @var{value} as its result. | ||
| 1290 | Otherwise, the above expansion would not obey the rules for the way | ||
| 1291 | @code{setf} is supposed to behave. | ||
| 1292 | |||
| 1293 | As a special (non-Common-Lisp) extension, a third argument of @code{t} | ||
| 1294 | to @code{defsetf} says that the @code{update-fn}'s return value is | ||
| 1295 | not suitable, so that the above @code{setf} should be expanded to | ||
| 1296 | something more like | ||
| 1297 | |||
| 1298 | @example | ||
| 1299 | (let ((temp @var{value})) | ||
| 1300 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} temp) | ||
| 1301 | temp) | ||
| 1302 | @end example | ||
| 1303 | |||
| 1304 | Some examples of the use of @code{defsetf}, drawn from the standard | ||
| 1305 | suite of setf methods, are: | ||
| 1306 | |||
| 1307 | @example | ||
| 1308 | (defsetf car setcar) | ||
| 1309 | (defsetf symbol-value set) | ||
| 1310 | (defsetf buffer-name rename-buffer t) | ||
| 1311 | @end example | ||
| 1312 | @end defmac | ||
| 1313 | |||
| 1314 | @defmac defsetf access-fn arglist (store-var) forms@dots{} | ||
| 1315 | This is the second, more complex, form of @code{defsetf}. It is | ||
| 1316 | rather like @code{defmacro} except for the additional @var{store-var} | ||
| 1317 | argument. The @var{forms} should return a Lisp form which stores | ||
| 1318 | the value of @var{store-var} into the generalized variable formed | ||
| 1319 | by a call to @var{access-fn} with arguments described by @var{arglist}. | ||
| 1320 | The @var{forms} may begin with a string which documents the @code{setf} | ||
| 1321 | method (analogous to the doc string that appears at the front of a | ||
| 1322 | function). | ||
| 1323 | |||
| 1324 | For example, the simple form of @code{defsetf} is shorthand for | ||
| 1325 | |||
| 1326 | @example | ||
| 1327 | (defsetf @var{access-fn} (&rest args) (store) | ||
| 1328 | (append '(@var{update-fn}) args (list store))) | ||
| 1329 | @end example | ||
| 1330 | |||
| 1331 | The Lisp form that is returned can access the arguments from | ||
| 1332 | @var{arglist} and @var{store-var} in an unrestricted fashion; | ||
| 1333 | macros like @code{setf} and @code{cl-incf} which invoke this | ||
| 1334 | setf-method will insert temporary variables as needed to make | ||
| 1335 | sure the apparent order of evaluation is preserved. | ||
| 1336 | |||
| 1337 | Another example drawn from the standard package: | ||
| 1338 | |||
| 1339 | @example | ||
| 1340 | (defsetf nth (n x) (store) | ||
| 1341 | (list 'setcar (list 'nthcdr n x) store)) | ||
| 1342 | @end example | ||
| 1343 | @end defmac | ||
| 1344 | |||
| 1345 | @defmac define-setf-method access-fn arglist forms@dots{} | ||
| 1346 | This is the most general way to create new place forms. When | ||
| 1347 | a @code{setf} to @var{access-fn} with arguments described by | ||
| 1348 | @var{arglist} is expanded, the @var{forms} are evaluated and | ||
| 1349 | must return a list of five items: | ||
| 1350 | |||
| 1351 | @enumerate | ||
| 1352 | @item | ||
| 1353 | A list of @dfn{temporary variables}. | ||
| 1354 | |||
| 1355 | @item | ||
| 1356 | A list of @dfn{value forms} corresponding to the temporary variables | ||
| 1357 | above. The temporary variables will be bound to these value forms | ||
| 1358 | as the first step of any operation on the generalized variable. | ||
| 1359 | |||
| 1360 | @item | ||
| 1361 | A list of exactly one @dfn{store variable} (generally obtained | ||
| 1362 | from a call to @code{gensym}). | ||
| 1363 | |||
| 1364 | @item | ||
| 1365 | A Lisp form which stores the contents of the store variable into | ||
| 1366 | the generalized variable, assuming the temporaries have been | ||
| 1367 | bound as described above. | ||
| 1368 | |||
| 1369 | @item | ||
| 1370 | A Lisp form which accesses the contents of the generalized variable, | ||
| 1371 | assuming the temporaries have been bound. | ||
| 1372 | @end enumerate | ||
| 1373 | |||
| 1374 | This is exactly like the Common Lisp macro of the same name, | ||
| 1375 | except that the method returns a list of five values rather | ||
| 1376 | than the five values themselves, since Emacs Lisp does not | ||
| 1377 | support Common Lisp's notion of multiple return values. | ||
| 1378 | |||
| 1379 | Once again, the @var{forms} may begin with a documentation string. | ||
| 1380 | |||
| 1381 | A setf-method should be maximally conservative with regard to | ||
| 1382 | temporary variables. In the setf-methods generated by | ||
| 1383 | @code{defsetf}, the second return value is simply the list of | ||
| 1384 | arguments in the place form, and the first return value is a | ||
| 1385 | list of a corresponding number of temporary variables generated | ||
| 1386 | by @code{cl-gensym}. Macros like @code{setf} and @code{cl-incf} which | ||
| 1387 | use this setf-method will optimize away most temporaries that | ||
| 1388 | turn out to be unnecessary, so there is little reason for the | ||
| 1389 | setf-method itself to optimize. | ||
| 1390 | @end defmac | ||
| 1391 | |||
| 1392 | @defun get-setf-method place &optional env | ||
| 1393 | This function returns the setf-method for @var{place}, by | ||
| 1394 | invoking the definition previously recorded by @code{defsetf} | ||
| 1395 | or @code{define-setf-method}. The result is a list of five | ||
| 1396 | values as described above. You can use this function to build | ||
| 1397 | your own @code{cl-incf}-like modify macros. (Actually, it is | ||
| 1398 | @c FIXME? | ||
| 1399 | better to use the internal functions @code{cl-setf-do-modify} | ||
| 1400 | and @code{cl-setf-do-store}, which are a bit easier to use and | ||
| 1401 | which also do a number of optimizations; consult the source | ||
| 1402 | code for the @code{cl-incf} function for a simple example.) | ||
| 1403 | |||
| 1404 | The argument @var{env} specifies the ``environment'' to be | ||
| 1405 | passed on to @code{macroexpand} if @code{get-setf-method} should | ||
| 1406 | need to expand a macro in @var{place}. It should come from | ||
| 1407 | an @code{&environment} argument to the macro or setf-method | ||
| 1408 | that called @code{get-setf-method}. | ||
| 1409 | |||
| 1410 | See also the source code for the setf-methods for @code{apply} | ||
| 1411 | and @code{substring}, each of which works by calling | ||
| 1412 | @code{get-setf-method} on a simpler case, then massaging | ||
| 1413 | the result in various ways. | ||
| 1414 | @end defun | ||
| 1415 | |||
| 1416 | Modern Common Lisp defines a second, independent way to specify | ||
| 1417 | the @code{setf} behavior of a function, namely ``@code{setf} | ||
| 1418 | functions'' whose names are lists @code{(setf @var{name})} | ||
| 1419 | rather than symbols. For example, @code{(defun (setf foo) @dots{})} | ||
| 1420 | defines the function that is used when @code{setf} is applied to | ||
| 1421 | @code{foo}. This package does not currently support @code{setf} | ||
| 1422 | functions. In particular, it is a compile-time error to use | ||
| 1423 | @code{setf} on a form which has not already been @code{defsetf}'d | ||
| 1424 | or otherwise declared; in newer Common Lisps, this would not be | ||
| 1425 | an error since the function @code{(setf @var{func})} might be | ||
| 1426 | defined later. | ||
| 1427 | 1216 | ||
| 1428 | @node Variable Bindings | 1217 | @node Variable Bindings |
| 1429 | @section Variable Bindings | 1218 | @section Variable Bindings |
| @@ -2672,8 +2461,8 @@ functions, by contrast, always return exactly one result. This | |||
| 2672 | package makes no attempt to emulate Common Lisp multiple return | 2461 | package makes no attempt to emulate Common Lisp multiple return |
| 2673 | values; Emacs versions of Common Lisp functions that return more | 2462 | values; Emacs versions of Common Lisp functions that return more |
| 2674 | than one value either return just the first value (as in | 2463 | than one value either return just the first value (as in |
| 2675 | @code{cl-compiler-macroexpand}) or return a list of values (as in | 2464 | @code{cl-compiler-macroexpand}) or return a list of values. |
| 2676 | @code{get-setf-method}). This package @emph{does} define placeholders | 2465 | This package @emph{does} define placeholders |
| 2677 | for the Common Lisp functions that work with multiple values, but | 2466 | for the Common Lisp functions that work with multiple values, but |
| 2678 | in Emacs Lisp these functions simply operate on lists instead. | 2467 | in Emacs Lisp these functions simply operate on lists instead. |
| 2679 | The @code{cl-values} form, for example, is a synonym for @code{list} | 2468 | The @code{cl-values} form, for example, is a synonym for @code{list} |
| @@ -5088,22 +4877,214 @@ Replaced by @code{cl-letf} (@pxref{Modify Macros}). | |||
| 5088 | @node Obsolete Setf Customization | 4877 | @node Obsolete Setf Customization |
| 5089 | @appendixsec Obsolete Ways to Customize Setf | 4878 | @appendixsec Obsolete Ways to Customize Setf |
| 5090 | 4879 | ||
| 5091 | This section describes some obsolete ways to extend @code{setf}. | 4880 | Common Lisp defines three macros, @code{define-modify-macro}, |
| 5092 | They are replaced by @file{gv.el} in Emacs 24.3. | 4881 | @code{defsetf}, and @code{define-setf-method}, that allow the |
| 4882 | user to extend generalized variables in various ways. | ||
| 4883 | In Emacs, these are obsolete, replaced by various features of | ||
| 4884 | @file{gv.el} in Emacs 24.3. | ||
| 4885 | @c FIXME details. | ||
| 4886 | |||
| 4887 | @defmac define-modify-macro name arglist function [doc-string] | ||
| 4888 | This macro defines a ``read-modify-write'' macro similar to | ||
| 4889 | @code{cl-incf} and @code{cl-decf}. The macro @var{name} is defined | ||
| 4890 | to take a @var{place} argument followed by additional arguments | ||
| 4891 | described by @var{arglist}. The call | ||
| 4892 | |||
| 4893 | @example | ||
| 4894 | (@var{name} @var{place} @var{args}...) | ||
| 4895 | @end example | ||
| 4896 | |||
| 4897 | @noindent | ||
| 4898 | will be expanded to | ||
| 5093 | 4899 | ||
| 5094 | @c FIXME. | 4900 | @example |
| 5095 | @defmac define-setf-method name arglist &rest body | 4901 | (cl-callf @var{func} @var{place} @var{args}...) |
| 5096 | Use @file{gv.el}. | 4902 | @end example |
| 4903 | |||
| 4904 | @noindent | ||
| 4905 | which in turn is roughly equivalent to | ||
| 4906 | |||
| 4907 | @example | ||
| 4908 | (setf @var{place} (@var{func} @var{place} @var{args}...)) | ||
| 4909 | @end example | ||
| 4910 | |||
| 4911 | For example: | ||
| 4912 | |||
| 4913 | @example | ||
| 4914 | (define-modify-macro cl-incf (&optional (n 1)) +) | ||
| 4915 | (define-modify-macro cl-concatf (&rest args) concat) | ||
| 4916 | @end example | ||
| 4917 | |||
| 4918 | Note that @code{&key} is not allowed in @var{arglist}, but | ||
| 4919 | @code{&rest} is sufficient to pass keywords on to the function. | ||
| 4920 | |||
| 4921 | Most of the modify macros defined by Common Lisp do not exactly | ||
| 4922 | follow the pattern of @code{define-modify-macro}. For example, | ||
| 4923 | @code{push} takes its arguments in the wrong order, and @code{pop} | ||
| 4924 | is completely irregular. You can define these macros ``by hand'' | ||
| 4925 | using @code{get-setf-method}, or consult the source | ||
| 4926 | to see how to use the internal @code{setf} building blocks. | ||
| 5097 | @end defmac | 4927 | @end defmac |
| 5098 | 4928 | ||
| 5099 | @defmac defsetf access-fn update-fn | 4929 | @defmac defsetf access-fn update-fn |
| 5100 | Use @file{gv.el}. | 4930 | This is the simpler of two @code{defsetf} forms. Where |
| 4931 | @var{access-fn} is the name of a function which accesses a place, | ||
| 4932 | this declares @var{update-fn} to be the corresponding store | ||
| 4933 | function. From now on, | ||
| 4934 | |||
| 4935 | @example | ||
| 4936 | (setf (@var{access-fn} @var{arg1} @var{arg2} @var{arg3}) @var{value}) | ||
| 4937 | @end example | ||
| 4938 | |||
| 4939 | @noindent | ||
| 4940 | will be expanded to | ||
| 4941 | |||
| 4942 | @example | ||
| 4943 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} @var{value}) | ||
| 4944 | @end example | ||
| 4945 | |||
| 4946 | @noindent | ||
| 4947 | The @var{update-fn} is required to be either a true function, or | ||
| 4948 | a macro which evaluates its arguments in a function-like way. Also, | ||
| 4949 | the @var{update-fn} is expected to return @var{value} as its result. | ||
| 4950 | Otherwise, the above expansion would not obey the rules for the way | ||
| 4951 | @code{setf} is supposed to behave. | ||
| 4952 | |||
| 4953 | As a special (non-Common-Lisp) extension, a third argument of @code{t} | ||
| 4954 | to @code{defsetf} says that the @code{update-fn}'s return value is | ||
| 4955 | not suitable, so that the above @code{setf} should be expanded to | ||
| 4956 | something more like | ||
| 4957 | |||
| 4958 | @example | ||
| 4959 | (let ((temp @var{value})) | ||
| 4960 | (@var{update-fn} @var{arg1} @var{arg2} @var{arg3} temp) | ||
| 4961 | temp) | ||
| 4962 | @end example | ||
| 4963 | |||
| 4964 | Some examples of the use of @code{defsetf}, drawn from the standard | ||
| 4965 | suite of setf methods, are: | ||
| 4966 | |||
| 4967 | @example | ||
| 4968 | (defsetf car setcar) | ||
| 4969 | (defsetf symbol-value set) | ||
| 4970 | (defsetf buffer-name rename-buffer t) | ||
| 4971 | @end example | ||
| 5101 | @end defmac | 4972 | @end defmac |
| 5102 | 4973 | ||
| 5103 | @defmac define-modify-macro name arglist function [doc-string] | 4974 | @defmac defsetf access-fn arglist (store-var) forms@dots{} |
| 5104 | Use @file{gv.el}. | 4975 | This is the second, more complex, form of @code{defsetf}. It is |
| 4976 | rather like @code{defmacro} except for the additional @var{store-var} | ||
| 4977 | argument. The @var{forms} should return a Lisp form which stores | ||
| 4978 | the value of @var{store-var} into the generalized variable formed | ||
| 4979 | by a call to @var{access-fn} with arguments described by @var{arglist}. | ||
| 4980 | The @var{forms} may begin with a string which documents the @code{setf} | ||
| 4981 | method (analogous to the doc string that appears at the front of a | ||
| 4982 | function). | ||
| 4983 | |||
| 4984 | For example, the simple form of @code{defsetf} is shorthand for | ||
| 4985 | |||
| 4986 | @example | ||
| 4987 | (defsetf @var{access-fn} (&rest args) (store) | ||
| 4988 | (append '(@var{update-fn}) args (list store))) | ||
| 4989 | @end example | ||
| 4990 | |||
| 4991 | The Lisp form that is returned can access the arguments from | ||
| 4992 | @var{arglist} and @var{store-var} in an unrestricted fashion; | ||
| 4993 | macros like @code{setf} and @code{cl-incf} which invoke this | ||
| 4994 | setf-method will insert temporary variables as needed to make | ||
| 4995 | sure the apparent order of evaluation is preserved. | ||
| 4996 | |||
| 4997 | Another example drawn from the standard package: | ||
| 4998 | |||
| 4999 | @example | ||
| 5000 | (defsetf nth (n x) (store) | ||
| 5001 | (list 'setcar (list 'nthcdr n x) store)) | ||
| 5002 | @end example | ||
| 5105 | @end defmac | 5003 | @end defmac |
| 5106 | 5004 | ||
| 5005 | @defmac define-setf-method access-fn arglist forms@dots{} | ||
| 5006 | This is the most general way to create new place forms. When | ||
| 5007 | a @code{setf} to @var{access-fn} with arguments described by | ||
| 5008 | @var{arglist} is expanded, the @var{forms} are evaluated and | ||
| 5009 | must return a list of five items: | ||
| 5010 | |||
| 5011 | @enumerate | ||
| 5012 | @item | ||
| 5013 | A list of @dfn{temporary variables}. | ||
| 5014 | |||
| 5015 | @item | ||
| 5016 | A list of @dfn{value forms} corresponding to the temporary variables | ||
| 5017 | above. The temporary variables will be bound to these value forms | ||
| 5018 | as the first step of any operation on the generalized variable. | ||
| 5019 | |||
| 5020 | @item | ||
| 5021 | A list of exactly one @dfn{store variable} (generally obtained | ||
| 5022 | from a call to @code{gensym}). | ||
| 5023 | |||
| 5024 | @item | ||
| 5025 | A Lisp form which stores the contents of the store variable into | ||
| 5026 | the generalized variable, assuming the temporaries have been | ||
| 5027 | bound as described above. | ||
| 5028 | |||
| 5029 | @item | ||
| 5030 | A Lisp form which accesses the contents of the generalized variable, | ||
| 5031 | assuming the temporaries have been bound. | ||
| 5032 | @end enumerate | ||
| 5033 | |||
| 5034 | This is exactly like the Common Lisp macro of the same name, | ||
| 5035 | except that the method returns a list of five values rather | ||
| 5036 | than the five values themselves, since Emacs Lisp does not | ||
| 5037 | support Common Lisp's notion of multiple return values. | ||
| 5038 | |||
| 5039 | Once again, the @var{forms} may begin with a documentation string. | ||
| 5040 | |||
| 5041 | A setf-method should be maximally conservative with regard to | ||
| 5042 | temporary variables. In the setf-methods generated by | ||
| 5043 | @code{defsetf}, the second return value is simply the list of | ||
| 5044 | arguments in the place form, and the first return value is a | ||
| 5045 | list of a corresponding number of temporary variables generated | ||
| 5046 | by @code{cl-gensym}. Macros like @code{setf} and @code{cl-incf} which | ||
| 5047 | use this setf-method will optimize away most temporaries that | ||
| 5048 | turn out to be unnecessary, so there is little reason for the | ||
| 5049 | setf-method itself to optimize. | ||
| 5050 | @end defmac | ||
| 5051 | |||
| 5052 | @defun get-setf-method place &optional env | ||
| 5053 | This function returns the setf-method for @var{place}, by | ||
| 5054 | invoking the definition previously recorded by @code{defsetf} | ||
| 5055 | or @code{define-setf-method}. The result is a list of five | ||
| 5056 | values as described above. You can use this function to build | ||
| 5057 | your own @code{cl-incf}-like modify macros. (Actually, it is | ||
| 5058 | @c FIXME? | ||
| 5059 | better to use the internal functions @code{cl-setf-do-modify} | ||
| 5060 | and @code{cl-setf-do-store}, which are a bit easier to use and | ||
| 5061 | which also do a number of optimizations; consult the source | ||
| 5062 | code for the @code{cl-incf} function for a simple example.) | ||
| 5063 | |||
| 5064 | The argument @var{env} specifies the ``environment'' to be | ||
| 5065 | passed on to @code{macroexpand} if @code{get-setf-method} should | ||
| 5066 | need to expand a macro in @var{place}. It should come from | ||
| 5067 | an @code{&environment} argument to the macro or setf-method | ||
| 5068 | that called @code{get-setf-method}. | ||
| 5069 | |||
| 5070 | See also the source code for the setf-methods for @code{apply} | ||
| 5071 | and @code{substring}, each of which works by calling | ||
| 5072 | @code{get-setf-method} on a simpler case, then massaging | ||
| 5073 | the result in various ways. | ||
| 5074 | @end defun | ||
| 5075 | |||
| 5076 | Modern Common Lisp defines a second, independent way to specify | ||
| 5077 | the @code{setf} behavior of a function, namely ``@code{setf} | ||
| 5078 | functions'' whose names are lists @code{(setf @var{name})} | ||
| 5079 | rather than symbols. For example, @code{(defun (setf foo) @dots{})} | ||
| 5080 | defines the function that is used when @code{setf} is applied to | ||
| 5081 | @code{foo}. This package does not currently support @code{setf} | ||
| 5082 | functions. In particular, it is a compile-time error to use | ||
| 5083 | @code{setf} on a form which has not already been @code{defsetf}'d | ||
| 5084 | or otherwise declared; in newer Common Lisps, this would not be | ||
| 5085 | an error since the function @code{(setf @var{func})} might be | ||
| 5086 | defined later. | ||
| 5087 | |||
| 5107 | 5088 | ||
| 5108 | @node GNU Free Documentation License | 5089 | @node GNU Free Documentation License |
| 5109 | @appendix GNU Free Documentation License | 5090 | @appendix GNU Free Documentation License |