First question: Is it reasonable to assume that a modern compiler for Common Lisp will usually compile
(mapcar #'fn ...) and
(map 'list #'fn ...) into the same code as
(mapc #'fn ...)? That is, is it reasonable to assume that a compiler will see that the return value is ignored, so that a new list doesn't need to be constructed? e.g. suppose that my source file contains this code:
(defun set-foo-5 (sym) (setf (get sym 'foo) 5)) (progn (mapcar #'set-foo-5 '(a b c)) (format t "All foos are five!~%"))
mapc be more efficient? I usually run SBCL, but my guess is that any good compiler would be able to figure out that there's no need to cons up a new list in this situation. Am I right?
Second question: In the same situation, should I assume that a modern compiler will usually compile
map 'list into the same code as
mapcar, as long as
'list is there in the source code, and not chosen at run time?
Third question: Similar question for other sequences. For example, if I replace the
mapcar line in the progn above with
(map 'vector #'set-foo-5 #(a b c)), should I assume that that the compiled code will not bother to construct a new vector?