From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Robert Thorpe Newsgroups: gmane.emacs.help Subject: Re: I'd like to marry while and mapcar... Date: Sat, 07 Feb 2015 21:09:38 +0000 Message-ID: <87a90pfmy5.fsf@robertthorpeconsulting.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1423343405 26968 80.91.229.3 (7 Feb 2015 21:10:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Feb 2015 21:10:05 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 07 22:10:01 2015 Return-path: Envelope-to: geh-help-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 1YKCdc-0000kP-Lj for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2015 22:10:00 +0100 Original-Received: from localhost ([::1]:54520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKCdb-00060b-Uf for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2015 16:09:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKCdQ-00060W-Ke for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 16:09:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKCdI-0002o6-SB for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 16:09:48 -0500 Original-Received: from outbound-smtp04.blacknight.com ([81.17.249.35]:47231) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKCdI-0002nx-La for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 16:09:40 -0500 Original-Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp04.blacknight.com (Postfix) with ESMTPS id A09F699065 for ; Sat, 7 Feb 2015 21:09:39 +0000 (UTC) Original-Received: (qmail 2100 invoked from network); 7 Feb 2015 21:09:39 -0000 Original-Received: from unknown (HELO RTLaptop) (rt@robertthorpeconsulting.com@[109.78.199.156]) by 81.17.254.9 with ESMTPSA (DHE-RSA-AES128-SHA encrypted, authenticated); 7 Feb 2015 21:09:39 -0000 In-Reply-To: (message from Drew Adams on Fri, 6 Feb 2015 14:49:18 -0800 (PST)) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 81.17.249.35 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:102564 Archived-At: Drew Adams writes: > FWIW, what you wrote in the first place, Marcin, is pretty > much what I would do. Call it Fortranesque, if you like. > But it's classic Lispiness, IMO. Lisp is not Haskell. I agree. I wrote a message yesterday saying many of the things Drew said here, but I accidentally deleted the buffer. Small loops of this sort are unlikely to be sources of error. "Improving" them by phrasing them as map operations has little benefit. I see two things wrong with the original code: > (let (current-include (list-of-includes ())) > (while (setq current-include (get-TeX-macro-arguments "include")) > (setq list-of-includes (append list-of-includes current-include))) > list-of-includes) Firstly, "push" is preferable for the 2nd setq as Drew mentions. More importantly, the function get-TeX-macro-arguments is badly named. It both gets arguments and it moves point across the buffer. It's name doesn't announce that it changes point. It's a long name already, but in my view it should announce that it changes point in the name. It may be best to have get-TeX-macro-arguments leave point unchanged and to move point explicitly separately. To do that, get-TeX-macro-arguments could return the buffer position after the last macro it found. >From your comment about the loop being "un-lispy", I expect your absorbed the idea that functional operations such as maps and reduces are preferable to loops. This is because loops often involve complex mutation of state, and that's error prone. It's most important to improve situations where there's complex or hidden mutation of state. In my view, simple loops are not really a problem. In Drew's code he nreverse's the list at the end. It would be best to avoid that. Does the subsequent code really need the list reversed? Or should that code really process the list in the opposite order? If that code is doing things the right way then what about get-TeX-macro-arguments? Should it move through the buffer from the beginning to the end or from end to beginning? BR, Robert Thorpe