diff options
| author | Kim F. Storm | 2005-06-20 21:44:59 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2005-06-20 21:44:59 +0000 |
| commit | 9afc7f1bc3cbb494759cb5bc55a16f88d2f300c3 (patch) | |
| tree | fd4edcfe5ceb6618df1edc10a6867d9911f0e95a | |
| parent | b7d1f38f89237ed8579e2961a661c7e089c0cf66 (diff) | |
| download | emacs-9afc7f1bc3cbb494759cb5bc55a16f88d2f300c3.tar.gz emacs-9afc7f1bc3cbb494759cb5bc55a16f88d2f300c3.zip | |
(Setting Variables): Any type of element can be
given order in add-to-ordered-list. Compare elements with eq.
| -rw-r--r-- | lispref/variables.texi | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lispref/variables.texi b/lispref/variables.texi index 8ee941892c9..31e42b59c79 100644 --- a/lispref/variables.texi +++ b/lispref/variables.texi | |||
| @@ -903,6 +903,55 @@ foo ;; @r{@code{foo} was changed.} | |||
| 903 | (setq @var{var} (cons @var{value} @var{var}))) | 903 | (setq @var{var} (cons @var{value} @var{var}))) |
| 904 | @end example | 904 | @end example |
| 905 | 905 | ||
| 906 | @defun add-to-ordered-list symbol element &optional order | ||
| 907 | This function sets the variable @var{symbol} by inserting | ||
| 908 | @var{element} into the old value, which must be a list, at the | ||
| 909 | position specified by @var{order}. If @var{element} is already a | ||
| 910 | member of the list, its position in the list is adjusted according | ||
| 911 | to @var{order}. Membership is tested using @code{eq}. | ||
| 912 | The valued returned is the resulting list, whether updated or not. | ||
| 913 | |||
| 914 | The @var{order} is a number, and the elements on list are sorted in | ||
| 915 | increasing numerical order. Elements without a numeric list order are | ||
| 916 | placed at the end of @var{symbol}. | ||
| 917 | |||
| 918 | The argument @var{symbol} is not implicitly quoted; | ||
| 919 | @code{add-to-ordered-list} is an ordinary function, like @code{set} | ||
| 920 | and unlike @code{setq}. Quote the argument yourself if that is what | ||
| 921 | you want. | ||
| 922 | |||
| 923 | The ordering information is stored in an alist on @var{symbol}'s | ||
| 924 | @code{list-order} property. | ||
| 925 | @end defun | ||
| 926 | |||
| 927 | Here's a scenario showing how to use @code{add-to-ordered-list}: | ||
| 928 | |||
| 929 | @example | ||
| 930 | (setq foo '()) | ||
| 931 | @result{} nil | ||
| 932 | |||
| 933 | (add-to-ordered-list 'foo 'a 1) ;; @r{Add @code{a}.} | ||
| 934 | @result{} (a) | ||
| 935 | |||
| 936 | (add-to-ordered-list 'foo 'c 3) ;; @r{Add @code{c}.} | ||
| 937 | @result{} (a c) | ||
| 938 | |||
| 939 | (add-to-ordered-list 'foo 'b 2) ;; @r{Add @code{b}.} | ||
| 940 | @result{} (a b c) | ||
| 941 | |||
| 942 | (add-to-ordered-list 'foo 'b 4) ;; @r{Move @code{b}.} | ||
| 943 | @result{} (a c b) | ||
| 944 | |||
| 945 | (add-to-ordered-list 'foo 'd) ;; @r{Append @code{d}.} | ||
| 946 | @result{} (a c b d) | ||
| 947 | |||
| 948 | (add-to-ordered-list 'foo 'b 2) ;; @r{Move @code{b}.} | ||
| 949 | @result{} (a b c d) | ||
| 950 | |||
| 951 | foo ;; @r{@code{foo} was changed.} | ||
| 952 | @result{} (a b c d) | ||
| 953 | @end example | ||
| 954 | |||
| 906 | @node Variable Scoping | 955 | @node Variable Scoping |
| 907 | @section Scoping Rules for Variable Bindings | 956 | @section Scoping Rules for Variable Bindings |
| 908 | 957 | ||