Received: from mx0.gmx.net (mx0.gmx.net [213.165.64.100]) by h1439878.stratoserver.net (8.14.2/8.14.2/Debian-2build1) with SMTP id p0OEOxUk007570 for ; Mon, 24 Jan 2011 15:25:01 +0100 Received: (qmail 4243 invoked by alias); 24 Jan 2011 14:24:54 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 24 Jan 2011 14:24:53 -0000 Received: from relay.uni-heidelberg.de (EHLO relay.uni-heidelberg.de) [129.206.100.212] by mx0.gmx.net (mx033) with SMTP; 24 Jan 2011 15:24:53 +0100 Received: from listserv.uni-heidelberg.de (listserv.uni-heidelberg.de [129.206.100.94]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id p0OEMgWF025551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 24 Jan 2011 15:22:42 +0100 Received: from listserv.uni-heidelberg.de (localhost.localdomain [127.0.0.1]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p0OEDtK2006208; Mon, 24 Jan 2011 15:22:34 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 906196 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Mon, 24 Jan 2011 15:22:34 +0100 Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p0OEMYvJ023244 for ; Mon, 24 Jan 2011 15:22:34 +0100 Received: from csep02.cliche.se (csep02.cliche.se [195.249.40.184]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id p0OEMG49010271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 24 Jan 2011 15:22:20 +0100 Received: from nova.local (unknown [130.239.119.132]) by csep02.cliche.se (Postfix) with ESMTP id 1FDCD186615 for ; Mon, 24 Jan 2011 15:00:55 +0100 (CET) User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; sv-SE; rv:1.9.2.11) Gecko/20101013 Thunderbird/3.1.5 MIME-Version: 1.0 References: <201101230906.p0N96bln024353@comedy.dante.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by listserv.uni-heidelberg.de id p0OEMYvJ023245 Message-ID: <4D3D8628.1000502@residenset.net> Date: Mon, 24 Jan 2011 15:01:12 +0100 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: =?ISO-8859-1?Q?Lars_Hellstr=F6m?= Subject: Re: \clist_length:N and \clist_nth:N To: LATEX-L@listserv.uni-heidelberg.de In-Reply-To: Precedence: list List-Help: , List-Unsubscribe: List-Subscribe: List-Owner: List-Archive: X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=5D7Q89H36p6i75npGen84eVAEFK/syJmFuaL1OLtauwJ5R/kaZ9HAe8peGX1DeqJL7BW4 1X28hmBsSaikXt0ebYfUaHmtXkk7HChP+4IT8t5foOuRzC8vyH8YP07l+7OgkY63m+qRZCiPVOZg mL0OA==V1; X-Resent-By: Forwarder X-Resent-For: rainer.schoepf@gmx.net X-Resent-To: rainer@rainer-schoepf.de Status: R X-Status: X-Keywords: X-UID: 6570 Will Robertson skrev 2011-01-23 10.12: > > From a question on tex.se (http://tex.stackexchange.com/q/8626/179), I > finally got around to writing \clist_length:N and \clist_nth:Nn functions > for extracting the length of a comma list, and extracting the n-th element > of the same. Both are expandable. (Code attached below.) > > Questions: names? I think "length" is a good one although it doesn't match > \tl_elt_count:N which is the equivalent for arbitrary token lists. Isn't this "elt" an implementation detail for that type of list (various \@elt tokens in 2e come to mind), and thus something that should be kept internal rather than canonised in a public interface? The clean solution for *both* types of list is rather to use "length". Moreover, I get a vague impression that the term `elt' is part of the pseudo-LISP heritage of LaTeX (emphasis on the "La"). If so, then that is IMHO another reason to avoid it, as that heritage is full of square pegs trying to fit in round holes. > I didn't write "clist_nth" with a view of it being the permanent name, but > now that I've written it I can't think of a (good) alternative. Any > thoughts? I think the verb you're looking for is "index", i.e., the command name would be clist_index. > I assume that other packages dealing with comma-lists (such as etoolbox, > etc.) contain similar functions. Is there functionality in l3clist that > we're currently missing? Since you're going the route of providing a numeric index interface to clists, some common operations within such an interface would be: first: Return index of first occurrence of a particular item within a clist, or -1 (given 0-based indices) if the item does not occur therein. last: Return index of last occurrence of a particular item within a clist, or -1 (given 0-based indices) if the item does not occur therein. (Note: Slightly trickier to implement.) range: Return a subrange of the clist, i.e., if \a_clist is "a,b,c,d" then \clist_range:Nnn\a_clist{1}{2} returns "b,c". (I don't have an opinion as to what might be the best sense of "return" in this case.) replace: Replace the material in a subrange of the clist by some other clist material. I can see first/last being useful for certain stack-style operations, e.g. cleartomark (like in Postscript, if you're familiar with that). But I would consider these fairly low priority features. Lars Hellström