Mercurial > hg > xemacs-beta
comparison man/lispref/functions.texi @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
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 several such functions; | 683 list or other collection. XEmacs Lisp has three 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. @xref{Creating Symbols}, for the function @code{mapatoms} which | 685 here. For the third mapping function, @code{mapatoms}, see |
686 maps over the symbols in an obarray. | 686 @ref{Creating Symbols}. |
687 | |
688 Mapping functions should never modify the sequence being mapped over. | |
689 The results are unpredictable. | |
690 | 687 |
691 @defun mapcar function sequence | 688 @defun mapcar function sequence |
692 @code{mapcar} applies @var{function} to each element of @var{sequence} | 689 @code{mapcar} applies @var{function} to each element of @var{sequence} |
693 in turn, and returns a list of the results. | 690 in turn, and returns a list of the results. |
694 | 691 |
695 The argument @var{sequence} can be any kind of sequence; that is, a | 692 The argument @var{sequence} may be a list, a vector, or a string. The |
696 list, a vector, a bit vector, or a string. The result is always a list. | 693 result is always a list. The length of the result is the same as the |
697 The length of the result is the same as the length of @var{sequence}. | 694 length of @var{sequence}. |
698 | 695 |
699 @smallexample | 696 @smallexample |
700 @group | 697 @group |
701 @exdent @r{For example:} | 698 @exdent @r{For example:} |
702 | 699 |
717 (defun mapcar* (f &rest args) | 714 (defun mapcar* (f &rest args) |
718 "Apply FUNCTION to successive cars of all ARGS. | 715 "Apply FUNCTION to successive cars of all ARGS. |
719 Return the list of results." | 716 Return the list of results." |
720 ;; @r{If no list is exhausted,} | 717 ;; @r{If no list is exhausted,} |
721 (if (not (memq 'nil args)) | 718 (if (not (memq 'nil args)) |
722 ;; @r{apply function to @sc{car}s.} | 719 ;; @r{apply function to @sc{CAR}s.} |
723 (cons (apply f (mapcar 'car args)) | 720 (cons (apply f (mapcar 'car args)) |
724 (apply 'mapcar* f | 721 (apply 'mapcar* f |
725 ;; @r{Recurse for rest of elements.} | 722 ;; @r{Recurse for rest of elements.} |
726 (mapcar 'cdr args))))) | 723 (mapcar 'cdr args))))) |
727 @end group | 724 @end group |
739 Between each pair of result strings, @code{mapconcat} inserts the string | 736 Between each pair of result strings, @code{mapconcat} inserts the string |
740 @var{separator}. Usually @var{separator} contains a space or comma or | 737 @var{separator}. Usually @var{separator} contains a space or comma or |
741 other suitable punctuation. | 738 other suitable punctuation. |
742 | 739 |
743 The argument @var{function} must be a function that can take one | 740 The argument @var{function} must be a function that can take one |
744 argument and return a string. The argument @var{sequence} can be any | 741 argument and return a string. |
745 kind of sequence; that is, a list, a vector, a bit vector, or a string. | |
746 | 742 |
747 @smallexample | 743 @smallexample |
748 @group | 744 @group |
749 (mapconcat 'symbol-name | 745 (mapconcat 'symbol-name |
750 '(The cat in the hat) | 746 '(The cat in the hat) |