comparison lispref/lists.texi @ 12067:73dc8205d259

*** empty log message ***
author Karl Heuer <kwzh@gnu.org>
date Mon, 05 Jun 1995 12:23:13 +0000
parents ff046980f017
children a6eb5f12b0f3
comparison
equal deleted inserted replaced
12066:b9b0b3f96dc2 12067:73dc8205d259
552 The second example shows that when the final argument is a sequence but 552 The second example shows that when the final argument is a sequence but
553 not a list, the sequence's elements do not become elements of the 553 not a list, the sequence's elements do not become elements of the
554 resulting list. Instead, the sequence becomes the final @sc{cdr}, like 554 resulting list. Instead, the sequence becomes the final @sc{cdr}, like
555 any other non-list final argument. 555 any other non-list final argument.
556 556
557 Integers are also allowed as arguments to @code{append}. They are 557 The @code{append} function also allows integers as arguments. It
558 converted to strings of digits making up the decimal print 558 converts them to strings of digits, making up the decimal print
559 representation of the integer, and these strings are then appended. 559 representation of the integer, and then uses the strings instead of the
560 Here's what happens: 560 original integers. @strong{Don't use this feature; we plan to eliminate
561 561 it. If you already use this feature, change your programs now!} The
562 @example 562 proper way to convert an integer to a decimal number in this way is with
563 @group 563 @code{format} (@pxref{Formatting Strings}) or @code{number-to-string}
564 (setq trees '(pine oak)) 564 (@pxref{String Conversion}).
565 @result{} (pine oak)
566 @end group
567 @group
568 (char-to-string 54)
569 @result{} "6"
570 @end group
571 @group
572 (setq longer-list (append trees 6 '(spruce)))
573 @result{} (pine oak 54 spruce)
574 @end group
575 @group
576 (setq x-list (append trees 6 6))
577 @result{} (pine oak 54 . 6)
578 @end group
579 @end example
580
581 This special case exists for compatibility with Mocklisp, and we don't
582 recommend you take advantage of it. If you want to convert an integer
583 in this way, use @code{format} (@pxref{Formatting Strings}) or
584 @code{number-to-string} (@pxref{String Conversion}).
585 @end defun 565 @end defun
586 566
587 @defun reverse list 567 @defun reverse list
588 This function creates a new list whose elements are the elements of 568 This function creates a new list whose elements are the elements of
589 @var{list}, but in reverse order. The original argument @var{list} is 569 @var{list}, but in reverse order. The original argument @var{list} is
1301 (cdr (assoc 2 needles-per-cluster)) 1281 (cdr (assoc 2 needles-per-cluster))
1302 @result{} ("Austrian Pine" "Red Pine") 1282 @result{} ("Austrian Pine" "Red Pine")
1303 @end smallexample 1283 @end smallexample
1304 @end defun 1284 @end defun
1305 1285
1286 @defun rassoc value alist
1287 This function returns the first association with value @var{value} in
1288 @var{alist}. It returns @code{nil} if no association in @var{alist} has
1289 a @sc{cdr} @code{equal} to @var{value}.
1290
1291 @code{rassoc} is like @code{assoc} except that it compares the @sc{cdr} of
1292 each @var{alist} association instead of the @sc{car}. You can think of
1293 this as ``reverse @code{assoc}'', finding the key for a given value.
1294 @end defun
1295
1306 @defun assq key alist 1296 @defun assq key alist
1307 This function is like @code{assoc} in that it returns the first 1297 This function is like @code{assoc} in that it returns the first
1308 association for @var{key} in @var{alist}, but it makes the comparison 1298 association for @var{key} in @var{alist}, but it makes the comparison
1309 using @code{eq} instead of @code{equal}. @code{assq} returns @code{nil} 1299 using @code{eq} instead of @code{equal}. @code{assq} returns @code{nil}
1310 if no association in @var{alist} has a @sc{car} @code{eq} to @var{key}. 1300 if no association in @var{alist} has a @sc{car} @code{eq} to @var{key}.