aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref
diff options
context:
space:
mode:
authorGlenn Morris2012-10-27 15:42:07 -0700
committerGlenn Morris2012-10-27 15:42:07 -0700
commit5887564d5b5c90a1bc2ff7c0a3412cb6f765d03e (patch)
tree7ab3c76065961be6d4b1d5a1dd606fdab6f4b9cc /doc/lispref
parent5b6887ad2afbdd7c1d855bbea36e2faeef2ad9b9 (diff)
downloademacs-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/ChangeLog6
-rw-r--r--doc/lispref/elisp.texi1
-rw-r--r--doc/lispref/lists.texi8
-rw-r--r--doc/lispref/variables.texi103
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 @@
12012-10-27 Glenn Morris <rgm@gnu.org> 12012-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
52012-10-27 Chong Yidong <cyd@gnu.org> 112012-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
490Scoping Rules for Variable Bindings 491Scoping 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
237This macro is a way of examining the @sc{car} of a list, 237This macro is a way of examining the @sc{car} of a list,
238and taking it off the list, all at once. 238and 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
240It operates on the list which is stored in the symbol @var{listname}. 244It operates on the list which is stored in the symbol @var{listname}.
241It removes this element from the list by setting @var{listname} 245It 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
683This macro provides an alternative way to write 687This 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
1955A @dfn{generalized variable} or @dfn{place form} is one of the many places
1956in Lisp memory where values can be stored. The simplest place form is
1957a regular Lisp variable. But the @sc{car}s and @sc{cdr}s of lists, elements
1958of arrays, properties of symbols, and many other locations are also
1959places where Lisp values are stored.
1960
1961@c FIXME? Not sure this is a useful analogy...
1962Generalized variables are analogous to ``lvalues'' in the C
1963language, where @samp{x = a[i]} gets an element from an array
1964and @samp{a[i] = x} stores an element using the same notation.
1965Just as certain forms like @code{a[i]} can be lvalues in C, there
1966is a set of forms that can be generalized variables in Lisp.
1967
1968The @code{setf} macro is the most basic way to operate on generalized
1969variables. The @code{setf} form is like @code{setq}, except that it
1970accepts arbitrary place forms on the left side rather than just
1971symbols. 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)},
1973but without having to remember two separate functions for setting and
1974accessing every type of place.
1975
1976@defmac setf [place form]@dots{}
1977This macro evaluates @var{form} and stores it in @var{place}, which
1978must be a valid generalized variable form. If there are several
1979@var{place} and @var{form} pairs, the assignments are done sequentially
1980just as with @code{setq}. @code{setf} returns the value of the last
1981@var{form}.
1982@end defmac
1983
1984The following Lisp forms will work as generalized variables, and
1985so may appear in the @var{place} argument of @code{setf}:
1986
1987@itemize
1988@item
1989A symbol naming a variable. In other words, @code{(setf x y)} is
1990exactly equivalent to @code{(setq x y)}, and @code{setq} itself is
1991strictly speaking redundant given that @code{setf} exists. Many
1992programmers continue to prefer @code{setq} for setting simple
1993variables, though, purely for stylistic or historical reasons.
1994The macro @code{(setf x y)} actually expands to @code{(setq x y)},
1995so there is no performance penalty for using it in compiled code.
1996
1997@item
1998A call to any of the following standard Lisp functions:
1999
2000@smallexample
2001car cdr nth nthcdr
2002caar cadr cdar cddr
2003aref elt get gethash
2004symbol-function symbol-value symbol-plist
2005@end smallexample
2006
2007@item
2008The following Emacs-specific functions are also @code{setf}-able:
2009
2010@smallexample
2011default-value process-get
2012frame-parameter process-sentinel
2013terminal-parameter window-buffer
2014keymap-parent window-display-table
2015match-data window-dedicated-p
2016overlay-get window-hscroll
2017overlay-start window-parameter
2018overlay-end window-point
2019process-buffer window-start
2020process-filter
2021@end smallexample
2022@end itemize
2023
2024@noindent
2025Using any forms other than these in the @var{place} argument to
2026@code{setf} will signal an error.
2027
2028Note that for @code{nthcdr} and @code{getf}, the list argument
2029of the function must itself be a valid @var{place} form. For
2030example, @code{(setf (nthcdr 0 foo) 7)} will set @code{foo} itself
2031to 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.
2037The macros @code{push} (@pxref{List Variables}) and @code{pop}
2038(@pxref{List Elements}) can manipulate generalized variables,
2039not just lists. @code{(pop @var{place})} removes and returns the first
2040element of the list stored in @var{place}. It is analogous to
2041@code{(prog1 (car @var{place}) (setf @var{place} (cdr @var{place})))},
2042except that it takes care to evaluate all subforms only once.
2043@code{(push @var{x} @var{place})} inserts @var{x} at the front of
2044the list stored in @var{place}. It is analogous to @code{(setf
2045@var{place} (cons @var{x} @var{place}))}, except for evaluation of the
2046subforms. Note that @code{push} and @code{pop} on an @code{nthcdr}
2047place can be used to insert or delete at any position in a list.
2048
2049The @file{cl-lib} library defines various extensions for generalized
2050variables, including additional @code{setf} places.
2051@xref{Generalized Variables,,, cl, Common Lisp Extensions}.