@end example
@end defun
-@need 1000
+@need 2000
@node List Elements
@section Accessing Elements of Lists
@example
(append '(x y) 'z)
- @result{} (x y z)
+ @result{} (x y . z)
(append '(x y) [z])
- @result{} (x y [z])
+ @result{} (x y . [z])
@end example
@noindent
resulting list. Instead, the sequence becomes the final @sc{cdr}, like
any other non-list final argument.
-Integers are also allowed as arguments to @code{append}. They are
-converted to strings of digits making up the decimal print
-representation of the integer, and these strings are then appended.
-Here's what happens:
-
-@example
-@group
-(setq trees '(pine oak))
- @result{} (pine oak)
-@end group
-@group
-(char-to-string 54)
- @result{} "6"
-@end group
-@group
-(setq longer-list (append trees 6 '(spruce)))
- @result{} (pine oak 54 spruce)
-@end group
-@group
-(setq x-list (append trees 6 6))
- @result{} (pine oak 54 . 6)
-@end group
-@end example
-
-This special case exists for compatibility with Mocklisp, and we don't
-recommend you take advantage of it. If you want to convert an integer
-in this way, use @code{format} (@pxref{Formatting Strings}) or
-@code{number-to-string} (@pxref{String Conversion}).
+The @code{append} function also allows integers as arguments. It
+converts them to strings of digits, making up the decimal print
+representation of the integer, and then uses the strings instead of the
+original integers. @strong{Don't use this feature; we plan to eliminate
+it. If you already use this feature, change your programs now!} The
+proper way to convert an integer to a decimal number in this way is with
+@code{format} (@pxref{Formatting Strings}) or @code{number-to-string}
+(@pxref{String Conversion}).
@end defun
@defun reverse list
@end group
@end example
+@need 4000
Here is the result in box notation:
@example
sorted order. If you wish to make a sorted copy without destroying the
original, copy it first with @code{copy-sequence} and then sort.
-Sorting does not change the @sc{car}s of the cons cells in @var{list};
-each cons cell in the result contains the same element that it contained
-before. The result differs from the argument @var{list} because the
-cells themselves have been reordered.
-
Sorting does not change the @sc{car}s of the cons cells in @var{list};
the cons cell that originally contained the element @code{a} in
@var{list} still has @code{a} in its @sc{car} after sorting, but it now
functions for sets include @code{memq} and @code{delq}, and their
@code{equal} versions, @code{member} and @code{delete}.
-@cindex CL note---lack @code{union}, @code{set}
+@cindex CL note---lack @code{union}, @code{intersection}
@quotation
@b{Common Lisp note:} Common Lisp has functions @code{union} (which
avoids duplicate elements) and @code{intersection} for set operations,
@end group
@group
(delq 'c sample-list)
- @result{} (a c (4))
+ @result{} (a b (4))
@end group
@group
sample-list
- @result{} (a c (4))
+ @result{} (a b (4))
@end group
@end example
-Note that @code{(delq 'b sample-list)} modifies @code{sample-list} to
-splice out the second element, but @code{(delq 'a sample-list)} does not
+Note that @code{(delq 'c sample-list)} modifies @code{sample-list} to
+splice out the third element, but @code{(delq 'a sample-list)} does not
splice anything---it just returns a shorter list. Don't assume that a
variable which formerly held the argument @var{list} now has fewer
elements, or that it still holds the original list! Instead, save the
@example
@group
(delete '(2) '((2) (1) (2)))
- @result{} '((1))
+ @result{} ((1))
@end group
@end example
@end defun
Lisp versions do not use @code{equal} to compare elements.
@end quotation
+ See also the function @code{add-to-list}, in @ref{Setting Variables},
+for another way to add an element to a list stored in a variable.
+
@node Association Lists
@section Association Lists
@cindex association list
@end smallexample
@end defun
+@defun rassoc value alist
+This function returns the first association with value @var{value} in
+@var{alist}. It returns @code{nil} if no association in @var{alist} has
+a @sc{cdr} @code{equal} to @var{value}.
+
+@code{rassoc} is like @code{assoc} except that it compares the @sc{cdr} of
+each @var{alist} association instead of the @sc{car}. You can think of
+this as ``reverse @code{assoc}'', finding the key for a given value.
+@end defun
+
@defun assq key alist
This function is like @code{assoc} in that it returns the first
association for @var{key} in @var{alist}, but it makes the comparison
(setq needles-per-cluster
'((2 . ("Austrian Pine" "Red Pine"))
(3 . ("Pitch Pine"))
+@end group
(5 . ("White Pine"))))
@result{}
((2 "Austrian Pine" "Red Pine")
@result{} nil
(cdr (car (cdr needles-per-cluster)))
@result{} ("Pitch Pine")
+@group
(eq (cdr (car (cdr needles-per-cluster)))
(cdr (car (cdr copy))))
@result{} t
@smallexample
@group
-(setcdr (assq 3 needles-per-cluster)
- '("Martian Vacuum Pine"))
+(setcdr (assq 3 copy) '("Martian Vacuum Pine"))
(cdr (assq 3 needles-per-cluster))
@result{} ("Pitch Pine")
@end group