GNU bug report logs -
#18175
files.el: use mapc in (mapcar 'switch-to-buffer ...)
Previous Next
Reported by: Ivan Shmakov <ivan <at> siamics.net>
Date: Sat, 2 Aug 2014 21:56:02 UTC
Severity: wishlist
Tags: patch
Fixed in version 25.1
Done: Ivan Shmakov <ivan <at> siamics.net>
Bug is archived. No further changes may be made.
Full log
Message #14 received at 18175 <at> debbugs.gnu.org (full text, mbox):
> > 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.
This bug report was last modified 10 years and 179 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.