mapc function &rest lists+ => list-1
mapcar function &rest lists+ => result-list
mapcan function &rest lists+ => concatenated-results
mapl function &rest lists+ => list-1
maplist function &rest lists+ => result-list
mapcon function &rest lists+ => concatenated-results
mapcar operates on successive elements of the lists. function is applied to the first element of each list, then to the second element of each list, and so on. The iteration terminates when the shortest list runs out, and excess elements in other lists are ignored. The value returned by mapcar is a list of the results of successive calls to function.
mapcar 首先将函数apply到每个列表的第一个元素,再将函数apply到每个列表的第二个元素。。
一直到最短的列表的最后一个元素。剩下的元素将被忽略。
它的结果是返回值不为nil的集合。
mapc is like mapcar except that the results of applying function are not accumulated. The list argument is returned.
mapc 和 mapcar 类似。不过返回的是第一个列表。
maplist is like mapcar except that function is applied to successive sublists of the lists. function is first applied to the lists themselves, and then to the cdr of each list, and then to the cdr of the cdr of each list, and so on.
maplist 和 mapcar 类似,不过首先将函数apply到每个列表,然后将函数apply到每个列表的cdr,然后将函数apply到每个列表的cddr。。
直到最短的一个列表为空为止。
mapl is like maplist except that the results of applying function are not accumulated; list-1 is returned.
mapl和maplist类似,但是返回的是第一个列表。
mapcan 和 mapcon 类似于 mapcar 和 maplist。它们使用 nconc 连接结果而不是 list。
Examples
(mapcar #'car '((1 a) (2 b) (3 c))) => (1 2 3)
(mapcar #'abs '(3 -4 2 -5 -6)) => (3 4 2 5 6)
(mapcar #'cons '(a b c) '(1 2 3)) => ((A . 1) (B . 2) (C . 3))
(maplist #'append '(1 2 3 4) '(1 2) '(1 2 3)) => ((1 2 3 4 1 2 1 2 3) (2 3 4 2 2 3))
(maplist #'(lambda (x) (cons 'foo x)) '(a b c d)) => ((FOO A B C D) (FOO B C D) (FOO C D) (FOO D))
(maplist #'(lambda (x) (if (member (car x) (cdr x)) 0 1)) '(a b a c d b c)) => (0 0 1 0 1 1 1)
(setq dummy nil) => NIL
(mapc #'(lambda (&rest x) (setq dummy (append dummy x)))
'(1 2 3 4)
'(a b c d e)
'(x y z)) => (1 2 3 4)
dummy => (1 A X 2 B Y 3 C Z)
(setq dummy nil) => NIL
(mapl #'(lambda (x) (push x dummy)) '(1 2 3 4)) => (1 2 3 4)
dummy => ((4) (3 4) (2 3 4) (1 2 3 4))
(mapcan #'(lambda (x y) (if (null x) nil (list x y)))
'(nil nil nil d e)
'(1 2 3 4 5 6)) => (D 4 E 5)
(mapcan #'(lambda (x) (and (numberp x) (list x)))
'(a 1 b c 3 4 d 5)) => (1 3 4 5)
(mapcon #'list '(1 2 3 4)) => ((1 2 3 4) (2 3 4) (3 4) (4))