From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] master b7fa6b1 1/4: Simplify use of FOR_EACH_TAIL Date: Sun, 5 Feb 2017 21:23:43 -0800 Organization: UCLA Computer Science Department Message-ID: References: <20170205213033.19755.8264@vcs.savannah.gnu.org> <20170205213034.20306220171@vcs.savannah.gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1486358676 11515 195.159.176.226 (6 Feb 2017 05:24:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 6 Feb 2017 05:24:36 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 To: Stefan Monnier , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 06 06:24:32 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cabmw-0002hV-K2 for ged-emacs-devel@m.gmane.org; Mon, 06 Feb 2017 06:24:30 +0100 Original-Received: from localhost ([::1]:45610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cabn0-0008KY-6V for ged-emacs-devel@m.gmane.org; Mon, 06 Feb 2017 00:24:34 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cabmL-0008KT-OT for emacs-devel@gnu.org; Mon, 06 Feb 2017 00:23:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cabmG-0001wo-QU for emacs-devel@gnu.org; Mon, 06 Feb 2017 00:23:53 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:36812) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cabmG-0001vs-Kq for emacs-devel@gnu.org; Mon, 06 Feb 2017 00:23:48 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A313E16007E; Sun, 5 Feb 2017 21:23:44 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id y-hgWNT5KQGv; Sun, 5 Feb 2017 21:23:43 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D9B3016007F; Sun, 5 Feb 2017 21:23:43 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id J-rjkFXQIxxA; Sun, 5 Feb 2017 21:23:43 -0800 (PST) Original-Received: from [192.168.1.9] (unknown [47.153.188.248]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id BD0DA16007E; Sun, 5 Feb 2017 21:23:43 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212017 Archived-At: Stefan Monnier wrote: > I'm surprised you > also decided to remove `tail`, since that one *is* used by the users of > the macro and forcing them to use `li.tail` instead of the variable of > their choice is rather odd. Logically, the variable is part of the iterator, not of the surrounding c= ode. I=20 did at first write a macro along the lines that you suggest, and also tri= ed=20 another variant where the user could specify a name of their choice for t= he=20 iterator, but in both cases this extra flexibility made the code a bit mo= re=20 verbose and was not that useful in practice. It would be easy to resurrec= t this=20 flexibility if needed (it doesn't affect efficiency, of course). Here's an example. At first, I wrote a revised version like this: Lisp_Object tail; FOR_EACH_TAIL (tail, list) if (EQ (XCAR (tail), elt)) return true; but this was annoying both because the user must declare 'tail', and beca= use=20 typically 'tail' should not survive the loop but the declaration forces i= t to=20 survive. I wanted something more like this: FOR_EACH_TAIL (tail, list) if (EQ (XCAR (tail), elt)) return true; where the macro declares 'tail' to be local to the loop. Unfortunately th= ere=20 doesn't seem to be any way to that in portable C. So I settled for this: FOR_EACH_TAIL (list) if (EQ (XCAR (li.tail), elt)) return true; which is even shorter than what I wanted, albeit with an 'li.tail' that l= ooks=20 odd at least at first. Although we could easily change things to let the = caller=20 specify a name, like this: FOR_EACH_TAIL (li, list) if (EQ (XCAR (li.tail), elt)) return true; it's rare to need different names for iterators, so it's unclear that thi= s extra=20 complexity would be helpful.