Operating on multiple lists?
On page 224 of Common Lisp: A Gentle Introduction to Symbolic Computation this example is given with the output.
> (mapcar #'(lambda (x y) (list x 'gets y))
'(fred wilma george diane)
'(job1 job2 job3 job4))
((FRED GETS JOB1)
(WILMA GETS JOB2)
(GEORGE GETS JOB3)
(DIANE GETS JOB4))
Is there a way to do the same thing in Emacs Lisp? The other example is also interesting because only 3 results, the number of elements in the shortest list, are produced.
> (mapcar #'+ '(1 2 3) '(10 20 30 40 50))
(11 22开发者_运维技巧 33)
Emacs has mapcar*
in the cl
package which does exactly that. Here is the documentation:
Apply FUNCTION to each element of SEQ, and make a list of the results. If there are several SEQs, FUNCTION is called with that many arguments, and mapping stops as soon as the shortest list runs out. With just one SEQ, this is like
mapcar
. With several, it is like the Common Lispmapcar
function extended to arbitrary sequence types.
精彩评论