diff options
| -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 | ||||
| -rw-r--r-- | doc/misc/ChangeLog | 10 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 235 |
6 files changed, 209 insertions, 154 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}. | ||
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index a0cfd675f0a..d447b0ca1ff 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2012-10-27 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * cl.texi (Control Structure): Update for setf now being in core. | ||
| 4 | (Setf Extensions): Rename from Basic Setf. Move much of the | ||
| 5 | former content to lispref/variables.texi. | ||
| 6 | (Modify Macros): Move pop, push details to lispref/variables.texi. | ||
| 7 | (Customizing Setf): Copyedits for setf etc being in core. | ||
| 8 | (Modify Macros, Efficiency Concerns, Porting Common Lisp): | ||
| 9 | Further namespaces updates. | ||
| 10 | |||
| 1 | 2012-10-26 Bastien Guerry <bzg@gnu.org> | 11 | 2012-10-26 Bastien Guerry <bzg@gnu.org> |
| 2 | 12 | ||
| 3 | * org.texi (Installation): Update the link to Org's ELPA. Also | 13 | * org.texi (Installation): Update the link to Org's ELPA. Also |
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 9200958a1b5..aba3f244012 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -57,7 +57,7 @@ developing GNU and promoting software freedom.'' | |||
| 57 | * Overview:: Basics, usage, etc. | 57 | * Overview:: Basics, usage, etc. |
| 58 | * Program Structure:: Arglists, @code{cl-eval-when}, @code{defalias}. | 58 | * Program Structure:: Arglists, @code{cl-eval-when}, @code{defalias}. |
| 59 | * Predicates:: @code{cl-typep} and @code{cl-equalp}. | 59 | * Predicates:: @code{cl-typep} and @code{cl-equalp}. |
| 60 | * Control Structure:: @code{setf}, @code{cl-do}, @code{cl-loop}, etc. | 60 | * Control Structure:: @code{cl-do}, @code{cl-loop}, etc. |
| 61 | * Macros:: Destructuring, @code{cl-define-compiler-macro}. | 61 | * Macros:: Destructuring, @code{cl-define-compiler-macro}. |
| 62 | * Declarations:: @code{cl-proclaim}, @code{cl-declare}, etc. | 62 | * Declarations:: @code{cl-proclaim}, @code{cl-declare}, etc. |
| 63 | * Symbols:: Property lists, @code{cl-gensym}. | 63 | * Symbols:: Property lists, @code{cl-gensym}. |
| @@ -801,17 +801,16 @@ In Emacs, use @code{memq} (or @code{cl-member}) and @code{assq} (or | |||
| 801 | 801 | ||
| 802 | @noindent | 802 | @noindent |
| 803 | The features described in the following sections implement | 803 | The features described in the following sections implement |
| 804 | various advanced control structures, including the powerful | 804 | various advanced control structures, including extensions to the |
| 805 | @c FIXME setf is now in gv.el, not cl. | 805 | standard @code{setf} facility, and a number of looping and conditional |
| 806 | @code{setf} facility and a number of looping and conditional | ||
| 807 | constructs. | 806 | constructs. |
| 808 | 807 | ||
| 809 | @c FIXME setf, push are standard now. | 808 | @c FIXME |
| 810 | @c lexical-let is obsolete; flet is not cl-flet. | 809 | @c lexical-let is obsolete; flet is not cl-flet. |
| 811 | @c values is not cl-values. | 810 | @c values is not cl-values. |
| 812 | @menu | 811 | @menu |
| 813 | * Assignment:: The @code{cl-psetq} form. | 812 | * Assignment:: The @code{cl-psetq} form. |
| 814 | * Generalized Variables:: @code{setf}, @code{cl-incf}, @code{push}, etc. | 813 | * Generalized Variables:: Extensions to generalized variables. |
| 815 | * Variable Bindings:: @code{cl-progv}, @code{lexical-let}, @code{flet}, @code{cl-macrolet}. | 814 | * Variable Bindings:: @code{cl-progv}, @code{lexical-let}, @code{flet}, @code{cl-macrolet}. |
| 816 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. | 815 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. |
| 817 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. | 816 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. |
| @@ -857,130 +856,74 @@ provides an even more convenient way to swap two variables; | |||
| 857 | @code{cl-psetq} always returns @code{nil}. | 856 | @code{cl-psetq} always returns @code{nil}. |
| 858 | @end defspec | 857 | @end defspec |
| 859 | 858 | ||
| 860 | @c FIXME now in gv.el. | ||
| 861 | @node Generalized Variables | 859 | @node Generalized Variables |
| 862 | @section Generalized Variables | 860 | @section Generalized Variables |
| 863 | 861 | ||
| 864 | @noindent | 862 | A @dfn{generalized variable} or @dfn{place form} is one of the many |
| 865 | A ``generalized variable'' or ``place form'' is one of the many places | 863 | places in Lisp memory where values can be stored. The simplest place |
| 866 | in Lisp memory where values can be stored. The simplest place form is | 864 | form is a regular Lisp variable. But the cars and cdrs of lists, |
| 867 | a regular Lisp variable. But the cars and cdrs of lists, elements | 865 | elements of arrays, properties of symbols, and many other locations |
| 868 | of arrays, properties of symbols, and many other locations are also | 866 | are also places where Lisp values are stored. For basic information, |
| 869 | places where Lisp values are stored. | 867 | @pxref{Generalized Variables,,,elisp,GNU Emacs Lisp Reference Manual}. |
| 870 | 868 | This package provides several additional features related to | |
| 871 | The @code{setf} form is like @code{setq}, except that it accepts | 869 | generalized variables. |
| 872 | arbitrary place forms on the left side rather than just | ||
| 873 | symbols. For example, @code{(setf (car a) b)} sets the car of | ||
| 874 | @code{a} to @code{b}, doing the same operation as @code{(setcar a b)} | ||
| 875 | but without having to remember two separate functions for setting | ||
| 876 | and accessing every type of place. | ||
| 877 | |||
| 878 | Generalized variables are analogous to ``lvalues'' in the C | ||
| 879 | language, where @samp{x = a[i]} gets an element from an array | ||
| 880 | and @samp{a[i] = x} stores an element using the same notation. | ||
| 881 | Just as certain forms like @code{a[i]} can be lvalues in C, there | ||
| 882 | is a set of forms that can be generalized variables in Lisp. | ||
| 883 | 870 | ||
| 884 | @menu | 871 | @menu |
| 885 | * Basic Setf:: @code{setf} and place forms. | 872 | * Setf Extensions:: Additional @code{setf} places. |
| 886 | * Modify Macros:: @code{cl-incf}, @code{push}, @code{cl-rotatef}, @code{letf}, @code{cl-callf}, etc. | 873 | * Modify Macros:: @code{cl-incf}, @code{cl-rotatef}, @code{letf}, @code{cl-callf}, etc. |
| 887 | * Customizing Setf:: @code{define-modify-macro}, @code{defsetf}, @code{define-setf-method}. | 874 | * Customizing Setf:: @code{define-modify-macro}, @code{defsetf}, @code{define-setf-method}. |
| 888 | @end menu | 875 | @end menu |
| 889 | 876 | ||
| 890 | @node Basic Setf | 877 | @node Setf Extensions |
| 891 | @subsection Basic Setf | 878 | @subsection Setf Extensions |
| 892 | |||
| 893 | @noindent | ||
| 894 | The @code{setf} macro is the most basic way to operate on generalized | ||
| 895 | variables. | ||
| 896 | |||
| 897 | @defspec setf [place form]@dots{} | ||
| 898 | This macro evaluates @var{form} and stores it in @var{place}, which | ||
| 899 | must be a valid generalized variable form. If there are several | ||
| 900 | @var{place} and @var{form} pairs, the assignments are done sequentially | ||
| 901 | just as with @code{setq}. @code{setf} returns the value of the last | ||
| 902 | @var{form}. | ||
| 903 | |||
| 904 | The following Lisp forms will work as generalized variables, and | ||
| 905 | so may appear in the @var{place} argument of @code{setf}: | ||
| 906 | 879 | ||
| 907 | @itemize @bullet | 880 | Several standard (e.g. @code{car}) and Emacs-specific |
| 908 | @item | 881 | (e.g. @code{window-point}) Lisp functions are @code{setf}-able by default. |
| 909 | A symbol naming a variable. In other words, @code{(setf x y)} is | 882 | This package defines @code{setf} handlers for several additional functions: |
| 910 | exactly equivalent to @code{(setq x y)}, and @code{setq} itself is | ||
| 911 | strictly speaking redundant now that @code{setf} exists. Many | ||
| 912 | programmers continue to prefer @code{setq} for setting simple | ||
| 913 | variables, though, purely for stylistic or historical reasons. | ||
| 914 | The macro @code{(setf x y)} actually expands to @code{(setq x y)}, | ||
| 915 | so there is no performance penalty for using it in compiled code. | ||
| 916 | 883 | ||
| 884 | @itemize | ||
| 917 | @item | 885 | @item |
| 918 | A call to any of the following Lisp functions: | 886 | Functions from @code{CL} itself: |
| 919 | |||
| 920 | @smallexample | 887 | @smallexample |
| 921 | car cdr caar .. cddddr | 888 | cl-caaar .. cl-cddddr cl-first .. cl-tenth |
| 922 | nth rest first .. tenth | 889 | cl-rest cl-get cl-getf cl-subseq |
| 923 | aref elt nthcdr | ||
| 924 | symbol-function symbol-value symbol-plist | ||
| 925 | get get* getf | ||
| 926 | gethash subseq | ||
| 927 | @end smallexample | 890 | @end smallexample |
| 928 | 891 | ||
| 929 | @noindent | ||
| 930 | Note that for @code{nthcdr} and @code{getf}, the list argument | ||
| 931 | of the function must itself be a valid @var{place} form. For | ||
| 932 | example, @code{(setf (nthcdr 0 foo) 7)} will set @code{foo} itself | ||
| 933 | to 7. Note that @code{push} and @code{pop} on an @code{nthcdr} | ||
| 934 | place can be used to insert or delete at any position in a list. | ||
| 935 | The use of @code{nthcdr} as a @var{place} form is an extension | ||
| 936 | to standard Common Lisp. | ||
| 937 | |||
| 938 | @item | 892 | @item |
| 939 | The following Emacs-specific functions are also @code{setf}-able. | 893 | General Emacs Lisp functions: |
| 940 | |||
| 941 | @smallexample | 894 | @smallexample |
| 942 | buffer-file-name marker-position | 895 | buffer-file-name getenv |
| 943 | buffer-modified-p match-data | 896 | buffer-modified-p global-key-binding |
| 944 | buffer-name mouse-position | 897 | buffer-name local-key-binding |
| 945 | buffer-string overlay-end | 898 | buffer-string mark |
| 946 | buffer-substring overlay-get | 899 | buffer-substring mark-marker |
| 947 | current-buffer overlay-start | 900 | current-buffer marker-position |
| 948 | current-case-table point | 901 | current-case-table mouse-position |
| 949 | current-column point-marker | 902 | current-column point |
| 950 | current-global-map point-max | 903 | current-global-map point-marker |
| 951 | current-input-mode point-min | 904 | current-input-mode point-max |
| 952 | current-local-map process-buffer | 905 | current-local-map point-min |
| 953 | current-window-configuration process-filter | 906 | current-window-configuration read-mouse-position |
| 954 | default-file-modes process-sentinel | 907 | default-file-modes screen-height |
| 955 | default-value read-mouse-position | 908 | documentation-property screen-width |
| 956 | documentation-property screen-height | 909 | face-background selected-window |
| 957 | extent-data screen-menubar | 910 | face-background-pixmap selected-screen |
| 958 | extent-end-position screen-width | 911 | face-font selected-frame |
| 959 | extent-start-position selected-window | 912 | face-foreground standard-case-table |
| 960 | face-background selected-screen | 913 | face-underline-p syntax-table |
| 961 | face-background-pixmap selected-frame | 914 | file-modes visited-file-modtime |
| 962 | face-font standard-case-table | 915 | frame-height window-height |
| 963 | face-foreground syntax-table | 916 | frame-parameters window-width |
| 964 | face-underline-p window-buffer | 917 | frame-visible-p x-get-secondary-selection |
| 965 | file-modes window-dedicated-p | 918 | frame-width x-get-selection |
| 966 | frame-height window-display-table | 919 | get-register |
| 967 | frame-parameters window-height | ||
| 968 | frame-visible-p window-hscroll | ||
| 969 | frame-width window-point | ||
| 970 | get-register window-start | ||
| 971 | getenv window-width | ||
| 972 | global-key-binding x-get-secondary-selection | ||
| 973 | keymap-parent x-get-selection | ||
| 974 | local-key-binding | ||
| 975 | mark | ||
| 976 | mark-marker | ||
| 977 | @end smallexample | 920 | @end smallexample |
| 978 | 921 | ||
| 979 | Most of these have directly corresponding ``set'' functions, like | 922 | Most of these have directly corresponding ``set'' functions, like |
| 980 | @code{use-local-map} for @code{current-local-map}, or @code{goto-char} | 923 | @code{use-local-map} for @code{current-local-map}, or @code{goto-char} |
| 981 | for @code{point}. A few, like @code{point-min}, expand to longer | 924 | for @code{point}. A few, like @code{point-min}, expand to longer |
| 982 | sequences of code when they are @code{setf}'d (@code{(narrow-to-region | 925 | sequences of code when they are used with @code{setf} |
| 983 | x (point-max))} in this case). | 926 | (@code{(narrow-to-region x (point-max))} in this case). |
| 984 | 927 | ||
| 985 | @item | 928 | @item |
| 986 | A call of the form @code{(substring @var{subplace} @var{n} [@var{m}])}, | 929 | A call of the form @code{(substring @var{subplace} @var{n} [@var{m}])}, |
| @@ -1007,6 +950,8 @@ a | |||
| 1007 | The generalized variable @code{buffer-substring}, listed above, | 950 | The generalized variable @code{buffer-substring}, listed above, |
| 1008 | also works in this way by replacing a portion of the current buffer. | 951 | also works in this way by replacing a portion of the current buffer. |
| 1009 | 952 | ||
| 953 | @c FIXME? Also `eq'? (see cl-lib.el) | ||
| 954 | |||
| 1010 | @item | 955 | @item |
| 1011 | A call of the form @code{(apply '@var{func} @dots{})} or | 956 | A call of the form @code{(apply '@var{func} @dots{})} or |
| 1012 | @code{(apply (function @var{func}) @dots{})}, where @var{func} | 957 | @code{(apply (function @var{func}) @dots{})}, where @var{func} |
| @@ -1025,9 +970,9 @@ Any form for which a @code{defsetf} or @code{define-setf-method} | |||
| 1025 | has been made. | 970 | has been made. |
| 1026 | @end itemize | 971 | @end itemize |
| 1027 | 972 | ||
| 1028 | Using any forms other than these in the @var{place} argument to | 973 | @c FIXME should this be in lispref? It seems self-evident. |
| 1029 | @code{setf} will signal an error. | 974 | @c Contrast with the cl-incf example later on. |
| 1030 | 975 | @c Here it really only serves as a constrast to wrong-order. | |
| 1031 | The @code{setf} macro takes care to evaluate all subforms in | 976 | The @code{setf} macro takes care to evaluate all subforms in |
| 1032 | the proper left-to-right order; for example, | 977 | the proper left-to-right order; for example, |
| 1033 | 978 | ||
| @@ -1056,15 +1001,14 @@ will be preserved. Adapting an example from Steele, given | |||
| 1056 | the form @code{(setf (wrong-order @var{a} @var{b}) 17)} will | 1001 | the form @code{(setf (wrong-order @var{a} @var{b}) 17)} will |
| 1057 | evaluate @var{b} first, then @var{a}, just as in an actual call | 1002 | evaluate @var{b} first, then @var{a}, just as in an actual call |
| 1058 | to @code{wrong-order}. | 1003 | to @code{wrong-order}. |
| 1059 | @end defspec | ||
| 1060 | 1004 | ||
| 1061 | @node Modify Macros | 1005 | @node Modify Macros |
| 1062 | @subsection Modify Macros | 1006 | @subsection Modify Macros |
| 1063 | 1007 | ||
| 1064 | @noindent | 1008 | @noindent |
| 1065 | This package defines a number of other macros besides @code{setf} | 1009 | This package defines a number of macros that operate on generalized |
| 1066 | that operate on generalized variables. Many are interesting and | 1010 | variables. Many are interesting and useful even when the @var{place} |
| 1067 | useful even when the @var{place} is just a variable name. | 1011 | is just a variable name. |
| 1068 | 1012 | ||
| 1069 | @defspec cl-psetf [place form]@dots{} | 1013 | @defspec cl-psetf [place form]@dots{} |
| 1070 | This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: | 1014 | This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: |
| @@ -1080,8 +1024,8 @@ by @var{x} if specified. The incremented value is returned. For | |||
| 1080 | example, @code{(cl-incf i)} is equivalent to @code{(setq i (1+ i))}, and | 1024 | example, @code{(cl-incf i)} is equivalent to @code{(setq i (1+ i))}, and |
| 1081 | @code{(cl-incf (car x) 2)} is equivalent to @code{(setcar x (+ (car x) 2))}. | 1025 | @code{(cl-incf (car x) 2)} is equivalent to @code{(setcar x (+ (car x) 2))}. |
| 1082 | 1026 | ||
| 1083 | Once again, care is taken to preserve the ``apparent'' order of | 1027 | As with @code{setf}, care is taken to preserve the ``apparent'' order |
| 1084 | evaluation. For example, | 1028 | of evaluation. For example, |
| 1085 | 1029 | ||
| 1086 | @example | 1030 | @example |
| 1087 | (cl-incf (aref vec (cl-incf i))) | 1031 | (cl-incf (aref vec (cl-incf i))) |
| @@ -1120,21 +1064,6 @@ This macro decrements the number stored in @var{place} by one, or | |||
| 1120 | by @var{x} if specified. | 1064 | by @var{x} if specified. |
| 1121 | @end defspec | 1065 | @end defspec |
| 1122 | 1066 | ||
| 1123 | @c FIXME move to lispref, add generalized variables. | ||
| 1124 | @defspec pop place | ||
| 1125 | This macro removes and returns the first element of the list stored | ||
| 1126 | in @var{place}. It is analogous to @code{(prog1 (car @var{place}) | ||
| 1127 | (setf @var{place} (cdr @var{place})))}, except that it takes care | ||
| 1128 | to evaluate all subforms only once. | ||
| 1129 | @end defspec | ||
| 1130 | |||
| 1131 | @c FIXME move to lispref, add generalized variables. | ||
| 1132 | @defspec push x place | ||
| 1133 | This macro inserts @var{x} at the front of the list stored in | ||
| 1134 | @var{place}. It is analogous to @code{(setf @var{place} (cons | ||
| 1135 | @var{x} @var{place}))}, except for evaluation of the subforms. | ||
| 1136 | @end defspec | ||
| 1137 | |||
| 1138 | @defspec cl-pushnew x place @t{&key :test :test-not :key} | 1067 | @defspec cl-pushnew x place @t{&key :test :test-not :key} |
| 1139 | This macro inserts @var{x} at the front of the list stored in | 1068 | This macro inserts @var{x} at the front of the list stored in |
| 1140 | @var{place}, but only if @var{x} was not @code{eql} to any | 1069 | @var{place}, but only if @var{x} was not @code{eql} to any |
| @@ -1143,19 +1072,19 @@ are interpreted in the same way as for @code{cl-adjoin}. | |||
| 1143 | @xref{Lists as Sets}. | 1072 | @xref{Lists as Sets}. |
| 1144 | @end defspec | 1073 | @end defspec |
| 1145 | 1074 | ||
| 1146 | @defspec shiftf place@dots{} newvalue | 1075 | @defspec cl-shiftf place@dots{} newvalue |
| 1147 | This macro shifts the @var{place}s left by one, shifting in the | 1076 | This macro shifts the @var{place}s left by one, shifting in the |
| 1148 | value of @var{newvalue} (which may be any Lisp expression, not just | 1077 | value of @var{newvalue} (which may be any Lisp expression, not just |
| 1149 | a generalized variable), and returning the value shifted out of | 1078 | a generalized variable), and returning the value shifted out of |
| 1150 | the first @var{place}. Thus, @code{(shiftf @var{a} @var{b} @var{c} | 1079 | the first @var{place}. Thus, @code{(cl-shiftf @var{a} @var{b} @var{c} |
| 1151 | @var{d})} is equivalent to | 1080 | @var{d})} is equivalent to |
| 1152 | 1081 | ||
| 1153 | @example | 1082 | @example |
| 1154 | (prog1 | 1083 | (prog1 |
| 1155 | @var{a} | 1084 | @var{a} |
| 1156 | (psetf @var{a} @var{b} | 1085 | (cl-psetf @var{a} @var{b} |
| 1157 | @var{b} @var{c} | 1086 | @var{b} @var{c} |
| 1158 | @var{c} @var{d})) | 1087 | @var{c} @var{d})) |
| 1159 | @end example | 1088 | @end example |
| 1160 | 1089 | ||
| 1161 | @noindent | 1090 | @noindent |
| @@ -1168,10 +1097,10 @@ This macro rotates the @var{place}s left by one in circular fashion. | |||
| 1168 | Thus, @code{(cl-rotatef @var{a} @var{b} @var{c} @var{d})} is equivalent to | 1097 | Thus, @code{(cl-rotatef @var{a} @var{b} @var{c} @var{d})} is equivalent to |
| 1169 | 1098 | ||
| 1170 | @example | 1099 | @example |
| 1171 | (psetf @var{a} @var{b} | 1100 | (cl-psetf @var{a} @var{b} |
| 1172 | @var{b} @var{c} | 1101 | @var{b} @var{c} |
| 1173 | @var{c} @var{d} | 1102 | @var{c} @var{d} |
| 1174 | @var{d} @var{a}) | 1103 | @var{d} @var{a}) |
| 1175 | @end example | 1104 | @end example |
| 1176 | 1105 | ||
| 1177 | @noindent | 1106 | @noindent |
| @@ -1318,9 +1247,8 @@ Most of the modify macros defined by Common Lisp do not exactly | |||
| 1318 | follow the pattern of @code{define-modify-macro}. For example, | 1247 | follow the pattern of @code{define-modify-macro}. For example, |
| 1319 | @code{push} takes its arguments in the wrong order, and @code{pop} | 1248 | @code{push} takes its arguments in the wrong order, and @code{pop} |
| 1320 | is completely irregular. You can define these macros ``by hand'' | 1249 | is completely irregular. You can define these macros ``by hand'' |
| 1321 | using @code{get-setf-method}, or consult the source file | 1250 | using @code{get-setf-method}, or consult the source |
| 1322 | @file{cl-macs.el} to see how to use the internal @code{setf} | 1251 | to see how to use the internal @code{setf} building blocks. |
| 1323 | building blocks. | ||
| 1324 | @end defspec | 1252 | @end defspec |
| 1325 | 1253 | ||
| 1326 | @defspec defsetf access-fn update-fn | 1254 | @defspec defsetf access-fn update-fn |
| @@ -4708,32 +4636,31 @@ user to modify @var{place}. | |||
| 4708 | 4636 | ||
| 4709 | @noindent | 4637 | @noindent |
| 4710 | Many of the advanced features of this package, such as @code{cl-defun}, | 4638 | Many of the advanced features of this package, such as @code{cl-defun}, |
| 4711 | @code{cl-loop}, and @code{setf}, are implemented as Lisp macros. In | 4639 | @code{cl-loop}, etc., are implemented as Lisp macros. In |
| 4712 | byte-compiled code, these complex notations will be expanded into | 4640 | byte-compiled code, these complex notations will be expanded into |
| 4713 | equivalent Lisp code which is simple and efficient. For example, | 4641 | equivalent Lisp code which is simple and efficient. For example, |
| 4714 | the forms | 4642 | the form |
| 4715 | 4643 | ||
| 4716 | @example | 4644 | @example |
| 4717 | (cl-incf i n) | 4645 | (cl-incf i n) |
| 4718 | (push x (car p)) | ||
| 4719 | @end example | 4646 | @end example |
| 4720 | 4647 | ||
| 4721 | @noindent | 4648 | @noindent |
| 4722 | are expanded at compile-time to the Lisp forms | 4649 | is expanded at compile-time to the Lisp form |
| 4723 | 4650 | ||
| 4724 | @example | 4651 | @example |
| 4725 | (setq i (+ i n)) | 4652 | (setq i (+ i n)) |
| 4726 | (setcar p (cons x (car p))) | ||
| 4727 | @end example | 4653 | @end example |
| 4728 | 4654 | ||
| 4729 | @noindent | 4655 | @noindent |
| 4730 | which are the most efficient ways of doing these respective operations | 4656 | which is the most efficient ways of doing this operation |
| 4731 | in Lisp. Thus, there is no performance penalty for using the more | 4657 | in Lisp. Thus, there is no performance penalty for using the more |
| 4732 | readable @code{cl-incf} and @code{push} forms in your compiled code. | 4658 | readable @code{cl-incf} form in your compiled code. |
| 4733 | 4659 | ||
| 4734 | @emph{Interpreted} code, on the other hand, must expand these macros | 4660 | @emph{Interpreted} code, on the other hand, must expand these macros |
| 4735 | every time they are executed. For this reason it is strongly | 4661 | every time they are executed. For this reason it is strongly |
| 4736 | recommended that code making heavy use of macros be compiled. | 4662 | recommended that code making heavy use of macros be compiled. |
| 4663 | @c FIXME why are they not labelled as macros? | ||
| 4737 | (The features labeled ``Special Form'' instead of ``Function'' in | 4664 | (The features labeled ``Special Form'' instead of ``Function'' in |
| 4738 | this manual are macros.) A loop using @code{cl-incf} a hundred times | 4665 | this manual are macros.) A loop using @code{cl-incf} a hundred times |
| 4739 | will execute considerably faster if compiled, and will also | 4666 | will execute considerably faster if compiled, and will also |
| @@ -4751,7 +4678,7 @@ all Lisp macros which appear in the form. The easiest way to use | |||
| 4751 | this function is to go to the @file{*scratch*} buffer and type, say, | 4678 | this function is to go to the @file{*scratch*} buffer and type, say, |
| 4752 | 4679 | ||
| 4753 | @example | 4680 | @example |
| 4754 | (cl-prettyexpand '(loop for x below 10 collect x)) | 4681 | (cl-prettyexpand '(cl-loop for x below 10 collect x)) |
| 4755 | @end example | 4682 | @end example |
| 4756 | 4683 | ||
| 4757 | @noindent | 4684 | @noindent |
| @@ -5104,7 +5031,7 @@ these forms: | |||
| 5104 | 5031 | ||
| 5105 | @example | 5032 | @example |
| 5106 | (let ((total 0)) (dolist (x my-list) (cl-incf total x)) total) | 5033 | (let ((total 0)) (dolist (x my-list) (cl-incf total x)) total) |
| 5107 | (loop for x in my-list sum x) | 5034 | (cl-loop for x in my-list sum x) |
| 5108 | @end example | 5035 | @end example |
| 5109 | 5036 | ||
| 5110 | While this would be mainly a stylistic choice in most Common Lisps, | 5037 | While this would be mainly a stylistic choice in most Common Lisps, |