comparison lispref/variables.texi @ 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 5565eb3af021
children fe7324a36ce5 b7da78284d4c
comparison
equal deleted inserted replaced
63606:d8676b0b6ab9 63607:443baf51aba7
901 @example 901 @example
902 (or (member @var{value} @var{var}) 902 (or (member @var{value} @var{var})
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
909 A given symbol @code{foo} can have several local variable bindings, 958 A given symbol @code{foo} can have several local variable bindings,
910 established at different places in the Lisp program, as well as a global 959 established at different places in the Lisp program, as well as a global