Subject: bug#18175: files.el: use mapc in (mapcar 'switch-to-buffer ...)

From: Drew Adams <[email-masked]>
Date: Sun, 3 Aug 2014 09:32:29 -0700 (PDT)

>  > By using `mapcar' you are signaling that you are interested in the
>  > return values of the argument function (and of course the resulting
>  > list of them).
> 
>  > By using `mapc' you are signaling that the values returned by the
>  > argument function are unimportant (only its side effects are
>  > significant).
> 
> 	How do you signal that the values returned by the argument
> 	function are unimportant, /and/ that you’re interested in the
> 	/original/ list instead?

By doing what you've done now.  Neither `mapc' nor `mapcar' says
that, on its own.

If return values are not important in some code then `mapc`,
`dolist`, `while`, or any number of other imperative/procedural
approaches are fine to use, and are often preferable.

Looking briefly at the original code and your patches now, I am
reminded that `find-file*' needs to return the list of buffers
(or the single buffer, for that case).  (As one user, for example,
I have code that expects the list of buffers to be returned.)

Your new patch does that, and it looks OK to me.  I did not spend
much time looking things over, so I might be missing something,
but it looks like you are not changing the external behavior (good).

It is fine to optimize things, but function interfaces (signatures
and behavior as viewed by calling functions or by users) should
not be altered.

You might want to make sure that the list of buffers returned is
the same in all cases as what is returned today.  The doc string
of `switch-to-buffer', for instance, seems to make a point of
saying that it returns the buffer switched to.  It does not say
that it returns the buffer indicated by argument BUFFER-OR-NAME.
Dunno why, but it does.

I'm guessing that that can make a difference only if the intended
buffer cannot be switched to (an error is raised).  And in that
case I'm guessing that the error raised would be handled
correctly by `find-file*'.  (I have not checked.)

You might also want to check to be sure that the effect on what
`buffer-list' returns (after the calls to `switch-buffer*')
remains the same.

The calls to `switch-to-buffer*' here do not use non-nil NORECORD,
so that at least can be ignored.  But maybe take a look, to make
sure.  Some commands and other functions depend on the buffer
order in `buffer-list', so this too should not be altered by
your proposed change.