Since installing Flycheck I've been bombarded with complaints about the elisp functions I've used reliably for years. This is the first one I can't understand. Here my function is designed to return the result of mapcar, not to produce side effects. The suggested replacement of mapc won't do what I need, though dolist could with a bit more effort.

Here's the code:

(defun synclient-get-touchpad-config ()
  "Return the touchpad config as a list of strings."
  (mapcar (lambda (s)
            (string-join (split-string s)))
          (seq-drop-while (lambda (s)
                            (not (string-prefix-p " " s)))
                          (process-lines "synclient" "-l")))

The exact error message is:

‘mapcar’ called for effect; use ‘mapc’ or ‘dolist’ instead (emacs-lisp)

What exactly is flycheck expecting me to do here?


It's mainly just a warning - really a suggestion.

It's pointing out that if you don't care to produce a new list from the original one, where the returned list's elements are the results of applying the function argument to the original list's elements, then you might as well just use dolist or mapc instead of mapcar.

In this case, your mapcar is, yes, returning a list of the function results. But your function synclient-get-touchpad-config doesn't do anything with that returned list. Your function instead returns the current buffer. According to your function, you didn't need to use mapcar - you made no use of its returned list. You could have just used mapc.

Using those functions is likely to be more performant. And they make clear to a human reader of your program that the results of applying the function to the list elements are unimportant (not used).

Besides being mainly a suggestion, it might sometimes let you know that you forgot to use the results of applying the function, if that was, in fact, your intention.

  • The point is that you didn't need mapcar, since you didn't use its returned list of values.
    – Drew
    Apr 21 '20 at 0:53
  • Thank you for the answer. Flycheck is trying my patience, but I'll stick with it for now. Apr 21 '20 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.