From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Shmakov Newsgroups: gmane.emacs.bugs Subject: bug#18175: files.el: use mapc in (mapcar 'switch-to-buffer ...) Date: Thu, 07 Aug 2014 19:15:34 +0000 Message-ID: <87ha1ot8kp.fsf@violet.siamics.net> References: <87r40yftes.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1407438983 30980 80.91.229.3 (7 Aug 2014 19:16:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 Aug 2014 19:16:23 +0000 (UTC) To: 18175@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 07 21:16:18 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XFTAe-0004zL-Gm for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Aug 2014 21:16:16 +0200 Original-Received: from localhost ([::1]:47891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFTAd-00069X-Tp for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Aug 2014 15:16:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFTAV-00069K-4u for bug-gnu-emacs@gnu.org; Thu, 07 Aug 2014 15:16:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFTAQ-0008NB-TA for bug-gnu-emacs@gnu.org; Thu, 07 Aug 2014 15:16:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFTAQ-0008Mk-Ii for bug-gnu-emacs@gnu.org; Thu, 07 Aug 2014 15:16:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XFTAQ-0006b9-6X for bug-gnu-emacs@gnu.org; Thu, 07 Aug 2014 15:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Aug 2014 19:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18175 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: wontfix Original-Received: via spool by 18175-submit@debbugs.gnu.org id=B18175.140743894725333 (code B ref 18175); Thu, 07 Aug 2014 19:16:02 +0000 Original-Received: (at 18175) by debbugs.gnu.org; 7 Aug 2014 19:15:47 +0000 Original-Received: from localhost ([127.0.0.1]:34287 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XFTAA-0006aW-8Q for submit@debbugs.gnu.org; Thu, 07 Aug 2014 15:15:46 -0400 Original-Received: from fely.am-1.org ([78.47.74.50]:49786) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XFTA6-0006aL-TK for 18175@debbugs.gnu.org; Thu, 07 Aug 2014 15:15:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=siamics.net; s=a2013295; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:Sender:References:Subject:To:From; bh=w4U3d7EzsgzBk5noi7WnegaLadVJakaIGOu3DX5GlQs=; b=MHBec09TSFOgY6fjk5ydXnq9Bi2tQZ/+6Dz9hp3jA6VEY75Cj5JNCbbSGeBqB8k+UDPR+k1PFMrRg1KpJoj/2EnZJ5oD1+QwW18P/clUtVWGVRhQUS1NX+xzRwFnyUqEQt3MpBOUq1BuypdNungTX1HhoJN5pXXGpZdi3R4x4Zs=; Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by fely.am-1.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XFTA5-0002aO-BJ for 18175@debbugs.gnu.org; Thu, 07 Aug 2014 19:15:41 +0000 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XFT9y-0007Im-EK for 18175@debbugs.gnu.org; Fri, 08 Aug 2014 02:15:34 +0700 In-Reply-To: (Stefan Monnier's message of "Wed, 06 Aug 2014 13:26:22 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:92280 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Stefan Monnier writes: >> Given that switch-to-buffer returns its argument, /and/ given that >> mapc returns the sequence it=E2=80=99s given, I suggest that the (mapcar >> 'switch-to-buffer LIST) forms in lisp/files.el be replaced with >> (mapc 'switch-to-buffer LIST), =E2=80=93 if only to avoid the unnecessa= ry >> consing when the list is effectively copied in the mapcar case. > Thanks, I think it's indeed a valid/correct optimization, but I > really dislike relying on mapc's return value (it really should not > return any value at all). I tend to disagree with that last part, =E2=80=93 it seems like a common idiom for a function (or, generally, =E2=80=93 a /form/; setq does that, for one thing) that=E2=80=99s used =E2=80=9Csolely=E2=80=9D for its side-e= ffects to return its =E2=80=9Cprimary=E2=80=9D argument, thus allowing for easy =E2=80=9Cchaining=E2=80=9D, like: (foo (bar 42 (baz data))) Instead of: (progn (foo data) (bar 42 data) (baz data)) Or something even more crude, like: (mapc (lambda (fn) (if (consp fn) (apply (car fn) `(,@(cdr fn) ,data)) (funcall fn data))) '(foo (bar 42) baz)) Surely, =E2=80=98mapc=E2=80=99 fits that pattern pretty well; cf.: (foo (bar 42 (baz lst))) (foo (mapc 'qux (baz lst))) > In this case, the optimization doesn't seem worth the inconvenient of > having a very unusual code (relying on mapc's return value), since > those few cons cells we save are drowned in the noise of all the code > run by switch-to-buffer. Yes. However, I believe that the last two hunks of the one another variant of the diff (MIMEd) actually make the intent to return the reverse of the list returned by find-file-noselect /clearer,/ =E2=80=93 although at the expense of adding one extra LoC in each case. --=20 FSF associate member #7257 http://boycottsystemd.org/ =E2=80=A6 3013 B6A0= 230E 334A --=-=-= Content-Type: text/x-diff Content-Disposition: inline --- a/lisp/files.el +++ b/lisp/files.el @@ -1428,7 +1428,7 @@ automatically choosing a major mode, use \\[find-file-literally]." (confirm-nonexistent-file-or-buffer))) (let ((value (find-file-noselect filename nil nil wildcards))) (if (listp value) - (mapcar 'switch-to-buffer (nreverse value)) + (mapc 'switch-to-buffer (nreverse value)) (switch-to-buffer value)))) (defun find-file-other-window (filename &optional wildcards) @@ -1450,8 +1450,9 @@ expand wildcards (if any) and visit multiple files." (if (listp value) (progn (setq value (nreverse value)) - (cons (switch-to-buffer-other-window (car value)) - (mapcar 'switch-to-buffer (cdr value)))) + (switch-to-buffer-other-window (car value)) + (mapc 'switch-to-buffer (cdr value)) + value) (switch-to-buffer-other-window value)))) (defun find-file-other-frame (filename &optional wildcards) @@ -1473,8 +1474,9 @@ expand wildcards (if any) and visit multiple files." (if (listp value) (progn (setq value (nreverse value)) - (cons (switch-to-buffer-other-frame (car value)) - (mapcar 'switch-to-buffer (cdr value)))) + (switch-to-buffer-other-frame (car value)) + (mapc 'switch-to-buffer (cdr value)) + value) (switch-to-buffer-other-frame value)))) (defun find-file-existing (filename) --=-=-=--