3

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")))
  (current-buffer))

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?

Drew
  • 75,699
  • 9
  • 109
  • 225

1 Answers1

4

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.

Drew
  • 75,699
  • 9
  • 109
  • 225