So far I have been using mapcar
to apply a function to all elements of a list, such as:
(mapcar (lambda (x) (* x x))
'(1 2 3 4 5))
;; => '(1 4 9 16 25)
Now I learned that there is also the mapc
function which does exactly the same, but does not return a new list, but the original one:
(mapc (lambda (x) (* x x))
'(1 2 3 4 5))
;; => '(1 2 3 4 5)
What's the intent of this function? When would I use mapc
instead of mapcar
if I am not able to access the result?
mapcar
here as well, would it? – Simla