[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A mapping function applies a given function to each element of a
list or other collection. Emacs Lisp has several such functions;
mapcar
and mapconcat
, which scan a list, are described
here. See section 8.3 Creating and Interning Symbols, for the function mapatoms
which
maps over the symbols in an obarray. See section 7.2 Hash Table Access, for the
function maphash
which maps over key/value associations in a
hash table.
These mapping functions do not allow char-tables because a char-table
is a sparse array whose nominal range of indices is very large. To map
over a char-table in a way that deals properly with its sparse nature,
use the function map-char-table
(see section 6.6 Char-Tables).
mapcar
applies function to each element of sequence
in turn, and returns a list of the results.
The argument sequence can be any kind of sequence except a char-table; that is, a list, a vector, a bool-vector, or a string. The result is always a list. The length of the result is the same as the length of sequence.
For example:
(mapcar 'car '((a b) (c d) (e f)))
=> (a c e)
(mapcar '1+ [1 2 3])
=> (2 3 4)
(mapcar 'char-to-string "abc")
=> ("a" "b" "c")
;; Call each function in |
mapc
is like mapcar
except that function is used for
side-effects only--the values it returns are ignored, not collected
into a list. mapc
always returns sequence.
mapconcat
applies function to each element of
sequence: the results, which must be strings, are concatenated.
Between each pair of result strings, mapconcat
inserts the string
separator. Usually separator contains a space or comma or
other suitable punctuation.
The argument function must be a function that can take one argument and return a string. The argument sequence can be any kind of sequence except a char-table; that is, a list, a vector, a bool-vector, or a string.
(mapconcat 'symbol-name '(The cat in the hat) " ") => "The cat in the hat" (mapconcat (function (lambda (x) (format "%c" (1+ x)))) "HAL-8000" "") => "IBM.9111" |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |