comparison man/lispref/functions.texi @ 434:9d177e8d4150 r21-2-25

Import from CVS: tag r21-2-25
author cvs
date Mon, 13 Aug 2007 11:30:53 +0200
parents 3ecd8885ac67
children 576fb035e263
comparison
equal deleted inserted replaced
433:892ca416f0fb 434:9d177e8d4150
678 @node Mapping Functions 678 @node Mapping Functions
679 @section Mapping Functions 679 @section Mapping Functions
680 @cindex mapping functions 680 @cindex mapping functions
681 681
682 A @dfn{mapping function} applies a given function to each element of a 682 A @dfn{mapping function} applies a given function to each element of a
683 list or other collection. XEmacs Lisp has three such functions; 683 list or other collection. XEmacs Lisp has several such functions;
684 @code{mapcar} and @code{mapconcat}, which scan a list, are described 684 @code{mapcar} and @code{mapconcat}, which scan a list, are described
685 here. For the third mapping function, @code{mapatoms}, see 685 here. @xref{Creating Symbols}, for the function @code{mapatoms} which
686 @ref{Creating Symbols}. 686 maps over the symbols in an obarray.
687
688 Mapping functions should never modify the sequence being mapped over.
689 The results are unpredictable.
687 690
688 @defun mapcar function sequence 691 @defun mapcar function sequence
689 @code{mapcar} applies @var{function} to each element of @var{sequence} 692 @code{mapcar} applies @var{function} to each element of @var{sequence}
690 in turn, and returns a list of the results. 693 in turn, and returns a list of the results.
691 694
692 The argument @var{sequence} may be a list, a vector, or a string. The 695 The argument @var{sequence} can be any kind of sequence; that is, a
693 result is always a list. The length of the result is the same as the 696 list, a vector, a bit vector, or a string. The result is always a list.
694 length of @var{sequence}. 697 The length of the result is the same as the length of @var{sequence}.
695 698
696 @smallexample 699 @smallexample
697 @group 700 @group
698 @exdent @r{For example:} 701 @exdent @r{For example:}
699 702
736 Between each pair of result strings, @code{mapconcat} inserts the string 739 Between each pair of result strings, @code{mapconcat} inserts the string
737 @var{separator}. Usually @var{separator} contains a space or comma or 740 @var{separator}. Usually @var{separator} contains a space or comma or
738 other suitable punctuation. 741 other suitable punctuation.
739 742
740 The argument @var{function} must be a function that can take one 743 The argument @var{function} must be a function that can take one
741 argument and return a string. 744 argument and return a string. The argument @var{sequence} can be any
745 kind of sequence; that is, a list, a vector, a bit vector, or a string.
742 746
743 @smallexample 747 @smallexample
744 @group 748 @group
745 (mapconcat 'symbol-name 749 (mapconcat 'symbol-name
746 '(The cat in the hat) 750 '(The cat in the hat)