aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2006-07-24 17:59:15 +0000
committerRichard M. Stallman2006-07-24 17:59:15 +0000
commite1eed9a446f77d37232bb435d15c42550fe5d457 (patch)
tree6197890ad88fb92497a81543f847f6d3478cddde
parent5e6f234c03df7e092b6ce40b84c8b3fb4d8e99f4 (diff)
downloademacs-e1eed9a446f77d37232bb435d15c42550fe5d457.tar.gz
emacs-e1eed9a446f77d37232bb435d15c42550fe5d457.zip
(Setting Variables): add-to-list and add-to-ordered-list moved to List
Variables node.
-rw-r--r--lispref/variables.texi99
1 files changed, 0 insertions, 99 deletions
diff --git a/lispref/variables.texi b/lispref/variables.texi
index 0106c8ec2c2..5c54701cdd4 100644
--- a/lispref/variables.texi
+++ b/lispref/variables.texi
@@ -858,105 +858,6 @@ always affects the most local existing binding.
858@end quotation 858@end quotation
859@end defun 859@end defun
860 860
861 One other function for setting a variable is designed to add
862an element to a list if it is not already present in the list.
863
864@defun add-to-list symbol element &optional append
865This function sets the variable @var{symbol} by consing @var{element}
866onto the old value, if @var{element} is not already a member of that
867value. It returns the resulting list, whether updated or not. The
868value of @var{symbol} had better be a list already before the call.
869Membership is tested using @code{equal}.
870
871Normally, if @var{element} is added, it is added to the front of
872@var{symbol}, but if the optional argument @var{append} is
873non-@code{nil}, it is added at the end.
874
875The argument @var{symbol} is not implicitly quoted; @code{add-to-list}
876is an ordinary function, like @code{set} and unlike @code{setq}. Quote
877the argument yourself if that is what you want.
878@end defun
879
880Here's a scenario showing how to use @code{add-to-list}:
881
882@example
883(setq foo '(a b))
884 @result{} (a b)
885
886(add-to-list 'foo 'c) ;; @r{Add @code{c}.}
887 @result{} (c a b)
888
889(add-to-list 'foo 'b) ;; @r{No effect.}
890 @result{} (c a b)
891
892foo ;; @r{@code{foo} was changed.}
893 @result{} (c a b)
894@end example
895
896 An equivalent expression for @code{(add-to-list '@var{var}
897@var{value})} is this:
898
899@example
900(or (member @var{value} @var{var})
901 (setq @var{var} (cons @var{value} @var{var})))
902@end example
903
904@defun add-to-ordered-list symbol element &optional order
905This function sets the variable @var{symbol} by inserting
906@var{element} into the old value, which must be a list, at the
907position specified by @var{order}. If @var{element} is already a
908member of the list, its position in the list is adjusted according
909to @var{order}. Membership is tested using @code{eq}.
910This function returns the resulting list, whether updated or not.
911
912The @var{order} is typically a number (integer or float), and the
913elements of the list are sorted in non-decreasing numerical order.
914
915@var{order} may also be omitted or @code{nil}. Then the numeric order
916of @var{element} stays unchanged if it already has one; otherwise,
917@var{element} has no numeric order. Elements without a numeric list
918order are placed at the end of the list, in no particular order.
919
920Any other value for @var{order} removes the numeric order of @var{element}
921if it already has one; otherwise, it is equivalent to @code{nil}.
922
923The argument @var{symbol} is not implicitly quoted;
924@code{add-to-ordered-list} is an ordinary function, like @code{set}
925and unlike @code{setq}. Quote the argument yourself if that is what
926you want.
927
928The ordering information is stored in a hash table on @var{symbol}'s
929@code{list-order} property.
930@end defun
931
932Here's a scenario showing how to use @code{add-to-ordered-list}:
933
934@example
935(setq foo '())
936 @result{} nil
937
938(add-to-ordered-list 'foo 'a 1) ;; @r{Add @code{a}.}
939 @result{} (a)
940
941(add-to-ordered-list 'foo 'c 3) ;; @r{Add @code{c}.}
942 @result{} (a c)
943
944(add-to-ordered-list 'foo 'b 2) ;; @r{Add @code{b}.}
945 @result{} (a b c)
946
947(add-to-ordered-list 'foo 'b 4) ;; @r{Move @code{b}.}
948 @result{} (a c b)
949
950(add-to-ordered-list 'foo 'd) ;; @r{Append @code{d}.}
951 @result{} (a c b d)
952
953(add-to-ordered-list 'foo 'e) ;; @r{Add @code{e}}.
954 @result{} (a c b e d)
955
956foo ;; @r{@code{foo} was changed.}
957 @result{} (a c b e d)
958@end example
959
960@node Variable Scoping 861@node Variable Scoping
961@section Scoping Rules for Variable Bindings 862@section Scoping Rules for Variable Bindings
962 863