[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [Index] | [ ? ] |
These functions, and one macro, provide convenient ways to modify a list which is stored in a variable.
This macro provides an alternative way to write (setq listname
(cons newelt listname))
.
(setq l '(a b)) ⇒ (a b) (push 'c l) ⇒ (c a b) l ⇒ (c a b) |
Two functions modify lists that are the values of variables.
This function sets the variable symbol by consing element onto
the old value, if element is not already a member of that value. It
returns the resulting list, whether updated or not. The value of
symbol had better be a list already before the call.
add-to-list
uses compare-fn to compare element against
existing list members; if compare-fn is nil
, it uses
equal
.
Normally, if element is added, it is added to the front of
symbol, but if the optional argument append is non-nil
,
it is added at the end.
The argument symbol is not implicitly quoted; add-to-list
is an
ordinary function, like set
and unlike setq
. Quote the
argument yourself if that is what you want.
Here's a scenario showing how to use add-to-list
:
(setq foo '(a b)) ⇒ (a b) (add-to-list 'foo 'c) ;; Add |
An equivalent expression for (add-to-list 'var value)
is
this:
(or (member value var) (setq var (cons value var))) |
This function sets the variable symbol by inserting element into
the old value, which must be a list, at the position specified by
order. If element is already a member of the list, its position
in the list is adjusted according to order. Membership is tested
using eq
. This function returns the resulting list, whether updated
or not.
The order is typically a number (integer or float), and the elements of the list are sorted in non-decreasing numerical order.
order may also be omitted or nil
. Then the numeric order of
element stays unchanged if it already has one; otherwise,
element has no numeric order. Elements without a numeric list order
are placed at the end of the list, in no particular order.
Any other value for order removes the numeric order of element
if it already has one; otherwise, it is equivalent to nil
.
The argument symbol is not implicitly quoted;
add-to-ordered-list
is an ordinary function, like set
and
unlike setq
. Quote the argument yourself if that is what you want.
The ordering information is stored in a hash table on symbol's
list-order
property.
Here's a scenario showing how to use add-to-ordered-list
:
(setq foo '()) ⇒ nil (add-to-ordered-list 'foo 'a 1) ;; Add |
[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [Index] | [ ? ] |
Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.