From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: I'd like to marry while and mapcar... Date: Fri, 6 Feb 2015 14:49:18 -0800 (PST) Message-ID: References: <87vbjfdwq7.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1423262990 16550 80.91.229.3 (6 Feb 2015 22:49:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 6 Feb 2015 22:49:50 +0000 (UTC) To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 06 23:49:49 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 1YJrie-000416-7p for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 23:49:48 +0100 Original-Received: from localhost ([::1]:50820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJriY-0006z0-Nm for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Feb 2015 17:49:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJriN-0006yO-Tf for help-gnu-emacs@gnu.org; Fri, 06 Feb 2015 17:49:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJriG-000463-2A for help-gnu-emacs@gnu.org; Fri, 06 Feb 2015 17:49:31 -0500 Original-Received: from userp1040.oracle.com ([156.151.31.81]:19144) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJriF-00045Z-RO for help-gnu-emacs@gnu.org; Fri, 06 Feb 2015 17:49:23 -0500 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t16MnKSc022307 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Feb 2015 22:49:21 GMT Original-Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t16MnJKD029762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 6 Feb 2015 22:49:20 GMT Original-Received: from ubhmt119.oracle.com (ubhmt119.oracle.com [156.151.24.24]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t16MnJch012908; Fri, 6 Feb 2015 22:49:19 GMT In-Reply-To: <87vbjfdwq7.fsf@wmi.amu.edu.pl> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8.2 (807160) [OL 12.0.6691.5000 (x86)] X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 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:102545 Archived-At: 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. This is what I would do: (let ((includes ()) include) (while (setq include (get-TeX-macro-arguments "include")) (push include includes)) (setq includes (nreverse includes))) I wouldn't bother with `(cl-)loop' or `mapcar' or `mapc' here. Since you have a function that gets the next thingie you want, and it returns nil when there are no more, there is no reason at all to use `catch'+`throw' here. `catch'+`throw' is useful when, e.g., you have an existing list that you iterate over (e.g., using `dolist'), and you do not want to continue iterating over the rest of that list as soon as you know that you no longer need to. Here is a typical, end-the-looping-early use of `catch'+`throw': (defun take (n xs) "Return a new list containing only the first N elements of list XS. If N is greater than the length of XS, return (a copy of) XS." (let ((takes ())) (catch 'take (dolist (x xs) (when (>=3D (length takes) n) (throw 'take takes)) (push x takes))) (setq takes (nreverse takes)))) Or if you don't want the inefficiency of evaluating `length' at each iteration, add a counter: (defun take (n xs) "..." (let ((takes ()) (len 0)) (catch 'take (dolist (x xs) (when (>=3D len n) (throw 'take takes)) (push x takes) (cl-incf len))) (setq takes (nreverse takes))))