changeset 63607:443baf51aba7

(Setting Variables): Any type of element can be given order in add-to-ordered-list. Compare elements with eq.
author Kim F. Storm <storm@cua.dk>
date Mon, 20 Jun 2005 21:44:59 +0000
parents d8676b0b6ab9
children 93b3f84bbcd1 5b54039912f4
files lispref/variables.texi
diffstat 1 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lispref/variables.texi	Mon Jun 20 21:44:38 2005 +0000
+++ b/lispref/variables.texi	Mon Jun 20 21:44:59 2005 +0000
@@ -903,6 +903,55 @@
     (setq @var{var} (cons @var{value} @var{var})))
 @end example
 
+@defun add-to-ordered-list symbol element &optional order
+This function sets the variable @var{symbol} by inserting
+@var{element} into the old value, which must be a list, at the
+position specified by @var{order}.  If @var{element} is already a
+member of the list, its position in the list is adjusted according
+to @var{order}.  Membership is tested using @code{eq}.
+The valued returned is the resulting list, whether updated or not.
+
+The @var{order} is a number, and the elements on list are sorted in
+increasing numerical order.  Elements without a numeric list order are
+placed at the end of @var{symbol}.
+
+The argument @var{symbol} is not implicitly quoted;
+@code{add-to-ordered-list} is an ordinary function, like @code{set}
+and unlike @code{setq}.  Quote the argument yourself if that is what
+you want.
+
+The ordering information is stored in an alist on @var{symbol}'s
+@code{list-order} property.
+@end defun
+
+Here's a scenario showing how to use @code{add-to-ordered-list}:
+
+@example
+(setq foo '())
+     @result{} nil
+
+(add-to-ordered-list 'foo 'a 1)     ;; @r{Add @code{a}.}
+     @result{} (a)
+
+(add-to-ordered-list 'foo 'c 3)     ;; @r{Add @code{c}.}
+     @result{} (a c)
+
+(add-to-ordered-list 'foo 'b 2)     ;; @r{Add @code{b}.}
+     @result{} (a b c)
+
+(add-to-ordered-list 'foo 'b 4)     ;; @r{Move @code{b}.}
+     @result{} (a c b)
+
+(add-to-ordered-list 'foo 'd)       ;; @r{Append @code{d}.}
+     @result{} (a c b d)
+
+(add-to-ordered-list 'foo 'b 2)     ;; @r{Move @code{b}.}
+     @result{} (a b c d)
+
+foo                       ;; @r{@code{foo} was changed.}
+     @result{} (a b c d)
+@end example
+
 @node Variable Scoping
 @section Scoping Rules for Variable Bindings