diff options
| author | Glenn Morris | 2012-10-27 15:42:07 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-10-27 15:42:07 -0700 |
| commit | 5887564d5b5c90a1bc2ff7c0a3412cb6f765d03e (patch) | |
| tree | 7ab3c76065961be6d4b1d5a1dd606fdab6f4b9cc /doc/lispref | |
| parent | 5b6887ad2afbdd7c1d855bbea36e2faeef2ad9b9 (diff) | |
| download | emacs-5887564d5b5c90a1bc2ff7c0a3412cb6f765d03e.tar.gz emacs-5887564d5b5c90a1bc2ff7c0a3412cb6f765d03e.zip | |
Move generalized variable documentation from misc/cl.texi to lispref
* doc/lispref/variables.texi (Generalized Variables): New section,
adapted from misc/cl.texi.
* doc/lispref/elisp.texi (Top): Add Generalized Variables to menu.
* doc/lispref/lists.texi (List Elements, List Variables):
Mention generalized variables.
* doc/misc/cl.texi (Control Structure): Update for setf now being in core.
(Setf Extensions): Rename from Basic Setf. Move much of the
former content to lispref/variables.texi.
(Modify Macros): Move pop, push details to lispref/variables.texi.
(Customizing Setf): Copyedits for setf etc being in core.
(Modify Macros, Efficiency Concerns, Porting Common Lisp):
Further namespaces updates.
Diffstat (limited to 'doc/lispref')
| -rw-r--r-- | doc/lispref/ChangeLog | 6 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 1 | ||||
| -rw-r--r-- | doc/lispref/lists.texi | 8 | ||||
| -rw-r--r-- | doc/lispref/variables.texi | 103 |
4 files changed, 118 insertions, 0 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 03922f2c02f..aea26248452 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2012-10-27 Glenn Morris <rgm@gnu.org> | 1 | 2012-10-27 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | * variables.texi (Generalized Variables): New section, | ||
| 4 | adapted from misc/cl.texi. | ||
| 5 | * elisp.texi (Top): Add Generalized Variables to menu. | ||
| 6 | * lists.texi (List Elements, List Variables): | ||
| 7 | Mention generalized variables. | ||
| 8 | |||
| 3 | * lists.texi (List Elements): Typo fix. | 9 | * lists.texi (List Elements): Typo fix. |
| 4 | 10 | ||
| 5 | 2012-10-27 Chong Yidong <cyd@gnu.org> | 11 | 2012-10-27 Chong Yidong <cyd@gnu.org> |
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index 1d1dab8faac..06a2ebfcaf8 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -486,6 +486,7 @@ Variables | |||
| 486 | * Variable Aliases:: Variables that are aliases for other variables. | 486 | * Variable Aliases:: Variables that are aliases for other variables. |
| 487 | * Variables with Restricted Values:: Non-constant variables whose value can | 487 | * Variables with Restricted Values:: Non-constant variables whose value can |
| 488 | @emph{not} be an arbitrary Lisp object. | 488 | @emph{not} be an arbitrary Lisp object. |
| 489 | * Generalized Variables:: Extending the concept of variables. | ||
| 489 | 490 | ||
| 490 | Scoping Rules for Variable Bindings | 491 | Scoping Rules for Variable Bindings |
| 491 | 492 | ||
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index eaef8cc1f8a..09948caaa13 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -236,6 +236,10 @@ This is in contrast to @code{cdr}, which signals an error if | |||
| 236 | @defmac pop listname | 236 | @defmac pop listname |
| 237 | This macro is a way of examining the @sc{car} of a list, | 237 | This macro is a way of examining the @sc{car} of a list, |
| 238 | and taking it off the list, all at once. | 238 | and taking it off the list, all at once. |
| 239 | @c FIXME I don't think is a particularly good way to do it, | ||
| 240 | @c but generalized variables have not been introduced yet. | ||
| 241 | (In fact, this macro can act on generalized variables, not just lists. | ||
| 242 | @xref{Generalized Variables}.) | ||
| 239 | 243 | ||
| 240 | It operates on the list which is stored in the symbol @var{listname}. | 244 | It operates on the list which is stored in the symbol @var{listname}. |
| 241 | It removes this element from the list by setting @var{listname} | 245 | It removes this element from the list by setting @var{listname} |
| @@ -682,6 +686,10 @@ to modify a list which is stored in a variable. | |||
| 682 | @defmac push newelt listname | 686 | @defmac push newelt listname |
| 683 | This macro provides an alternative way to write | 687 | This macro provides an alternative way to write |
| 684 | @code{(setq @var{listname} (cons @var{newelt} @var{listname}))}. | 688 | @code{(setq @var{listname} (cons @var{newelt} @var{listname}))}. |
| 689 | @c FIXME I don't think is a particularly good way to do it, | ||
| 690 | @c but generalized variables have not been introduced yet. | ||
| 691 | (In fact, this macro can act on generalized variables, not just lists. | ||
| 692 | @xref{Generalized Variables}.) | ||
| 685 | 693 | ||
| 686 | @example | 694 | @example |
| 687 | (setq l '(a b)) | 695 | (setq l '(a b)) |
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 1c0abcb8e66..1ffb1f7ffcb 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -41,6 +41,7 @@ representing the variable. | |||
| 41 | * Variable Aliases:: Variables that are aliases for other variables. | 41 | * Variable Aliases:: Variables that are aliases for other variables. |
| 42 | * Variables with Restricted Values:: Non-constant variables whose value can | 42 | * Variables with Restricted Values:: Non-constant variables whose value can |
| 43 | @emph{not} be an arbitrary Lisp object. | 43 | @emph{not} be an arbitrary Lisp object. |
| 44 | * Generalized Variables:: Extending the concept of variables. | ||
| 44 | @end menu | 45 | @end menu |
| 45 | 46 | ||
| 46 | @node Global Variables | 47 | @node Global Variables |
| @@ -1946,3 +1947,105 @@ Attempting to assign them any other value will result in an error: | |||
| 1946 | (setq undo-limit 1000.0) | 1947 | (setq undo-limit 1000.0) |
| 1947 | @error{} Wrong type argument: integerp, 1000.0 | 1948 | @error{} Wrong type argument: integerp, 1000.0 |
| 1948 | @end example | 1949 | @end example |
| 1950 | |||
| 1951 | @c FIXME? Not sure this is the right place for this section. | ||
| 1952 | @node Generalized Variables | ||
| 1953 | @section Generalized Variables | ||
| 1954 | |||
| 1955 | A @dfn{generalized variable} or @dfn{place form} is one of the many places | ||
| 1956 | in Lisp memory where values can be stored. The simplest place form is | ||
| 1957 | a regular Lisp variable. But the @sc{car}s and @sc{cdr}s of lists, elements | ||
| 1958 | of arrays, properties of symbols, and many other locations are also | ||
| 1959 | places where Lisp values are stored. | ||
| 1960 | |||
| 1961 | @c FIXME? Not sure this is a useful analogy... | ||
| 1962 | Generalized variables are analogous to ``lvalues'' in the C | ||
| 1963 | language, where @samp{x = a[i]} gets an element from an array | ||
| 1964 | and @samp{a[i] = x} stores an element using the same notation. | ||
| 1965 | Just as certain forms like @code{a[i]} can be lvalues in C, there | ||
| 1966 | is a set of forms that can be generalized variables in Lisp. | ||
| 1967 | |||
| 1968 | The @code{setf} macro is the most basic way to operate on generalized | ||
| 1969 | variables. The @code{setf} form is like @code{setq}, except that it | ||
| 1970 | accepts arbitrary place forms on the left side rather than just | ||
| 1971 | symbols. For example, @code{(setf (car a) b)} sets the car of | ||
| 1972 | @code{a} to @code{b}, doing the same operation as @code{(setcar a b)}, | ||
| 1973 | but without having to remember two separate functions for setting and | ||
| 1974 | accessing every type of place. | ||
| 1975 | |||
| 1976 | @defmac setf [place form]@dots{} | ||
| 1977 | This macro evaluates @var{form} and stores it in @var{place}, which | ||
| 1978 | must be a valid generalized variable form. If there are several | ||
| 1979 | @var{place} and @var{form} pairs, the assignments are done sequentially | ||
| 1980 | just as with @code{setq}. @code{setf} returns the value of the last | ||
| 1981 | @var{form}. | ||
| 1982 | @end defmac | ||
| 1983 | |||
| 1984 | The following Lisp forms will work as generalized variables, and | ||
| 1985 | so may appear in the @var{place} argument of @code{setf}: | ||
| 1986 | |||
| 1987 | @itemize | ||
| 1988 | @item | ||
| 1989 | A symbol naming a variable. In other words, @code{(setf x y)} is | ||
| 1990 | exactly equivalent to @code{(setq x y)}, and @code{setq} itself is | ||
| 1991 | strictly speaking redundant given that @code{setf} exists. Many | ||
| 1992 | programmers continue to prefer @code{setq} for setting simple | ||
| 1993 | variables, though, purely for stylistic or historical reasons. | ||
| 1994 | The macro @code{(setf x y)} actually expands to @code{(setq x y)}, | ||
| 1995 | so there is no performance penalty for using it in compiled code. | ||
| 1996 | |||
| 1997 | @item | ||
| 1998 | A call to any of the following standard Lisp functions: | ||
| 1999 | |||
| 2000 | @smallexample | ||
| 2001 | car cdr nth nthcdr | ||
| 2002 | caar cadr cdar cddr | ||
| 2003 | aref elt get gethash | ||
| 2004 | symbol-function symbol-value symbol-plist | ||
| 2005 | @end smallexample | ||
| 2006 | |||
| 2007 | @item | ||
| 2008 | The following Emacs-specific functions are also @code{setf}-able: | ||
| 2009 | |||
| 2010 | @smallexample | ||
| 2011 | default-value process-get | ||
| 2012 | frame-parameter process-sentinel | ||
| 2013 | terminal-parameter window-buffer | ||
| 2014 | keymap-parent window-display-table | ||
| 2015 | match-data window-dedicated-p | ||
| 2016 | overlay-get window-hscroll | ||
| 2017 | overlay-start window-parameter | ||
| 2018 | overlay-end window-point | ||
| 2019 | process-buffer window-start | ||
| 2020 | process-filter | ||
| 2021 | @end smallexample | ||
| 2022 | @end itemize | ||
| 2023 | |||
| 2024 | @noindent | ||
| 2025 | Using any forms other than these in the @var{place} argument to | ||
| 2026 | @code{setf} will signal an error. | ||
| 2027 | |||
| 2028 | Note that for @code{nthcdr} and @code{getf}, the list argument | ||
| 2029 | of the function must itself be a valid @var{place} form. For | ||
| 2030 | example, @code{(setf (nthcdr 0 foo) 7)} will set @code{foo} itself | ||
| 2031 | to 7. | ||
| 2032 | @c The use of @code{nthcdr} as a @var{place} form is an extension | ||
| 2033 | @c to standard Common Lisp. | ||
| 2034 | |||
| 2035 | @c FIXME I don't think is a particularly good way to do it, | ||
| 2036 | @c but these macros are introduced before gvs are. | ||
| 2037 | The macros @code{push} (@pxref{List Variables}) and @code{pop} | ||
| 2038 | (@pxref{List Elements}) can manipulate generalized variables, | ||
| 2039 | not just lists. @code{(pop @var{place})} removes and returns the first | ||
| 2040 | element of the list stored in @var{place}. It is analogous to | ||
| 2041 | @code{(prog1 (car @var{place}) (setf @var{place} (cdr @var{place})))}, | ||
| 2042 | except that it takes care to evaluate all subforms only once. | ||
| 2043 | @code{(push @var{x} @var{place})} inserts @var{x} at the front of | ||
| 2044 | the list stored in @var{place}. It is analogous to @code{(setf | ||
| 2045 | @var{place} (cons @var{x} @var{place}))}, except for evaluation of the | ||
| 2046 | subforms. Note that @code{push} and @code{pop} on an @code{nthcdr} | ||
| 2047 | place can be used to insert or delete at any position in a list. | ||
| 2048 | |||
| 2049 | The @file{cl-lib} library defines various extensions for generalized | ||
| 2050 | variables, including additional @code{setf} places. | ||
| 2051 | @xref{Generalized Variables,,, cl, Common Lisp Extensions}. | ||