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 p0NFWAFg028484 for ; Sun, 23 Jan 2011 16:32:12 +0100 Received: (qmail 26530 invoked by alias); 23 Jan 2011 15:32:05 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 23 Jan 2011 15:32:05 -0000 Received: from relay.uni-heidelberg.de (EHLO relay.uni-heidelberg.de) [129.206.100.212] by mx0.gmx.net (mx061) with SMTP; 23 Jan 2011 16:32:05 +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 p0NFTKGl026375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 23 Jan 2011 16:29:20 +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 p0NC14II017349; Sun, 23 Jan 2011 16:29:08 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 857567 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Sun, 23 Jan 2011 16:29:08 +0100 Received: from relay.uni-heidelberg.de (relay.uni-heidelberg.de [129.206.100.212]) by listserv.uni-heidelberg.de (8.13.1/8.13.1) with ESMTP id p0NFT8Gt006309 for ; Sun, 23 Jan 2011 16:29:08 +0100 Received: from lon1-post-3.mail.demon.net (lon1-post-3.mail.demon.net [195.173.77.150]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id p0NFSrp4026126 for ; Sun, 23 Jan 2011 16:28:57 +0100 Received: from morningstar2.demon.co.uk ([80.176.134.7] helo=palladium.local) by lon1-post-3.mail.demon.net with esmtp (Exim 4.69) id 1Ph1s4-0000Pc-fi; Sun, 23 Jan 2011 15:28:53 +0000 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 References: <201101230906.p0N96bln024353@comedy.dante.de> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4D3C4934.50606@morningstar2.co.uk> Date: Sun, 23 Jan 2011 15:28:52 +0000 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Joseph Wright 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=5D7Q89H36p4U4jfdfC5HDevlx1X2sAZgP9e9F2VTUYI/FLDAh5vXTVin+wznIYULO4W8f iu4UIHVeutAdNYNyhIIRpjhB4NMqCt7OvFNAZ3Em9oZmuR2zOKGeZpAGdnSMvI6CR2LHXlIcSoSO ckeoA==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: 6567 On 23/01/2011 09:12, Will Robertson wrote: > Begin forwarded message: > >> Subject: [l3svn] r2135 - add \clist_length:N and \clist_nth:N to l3candidates >> Author: will >> Date: 2011-01-23 10:06:37 +0100 (Sun, 23 Jan 2011) >> New Revision: 2135 >> >> Modified: >> trunk/l3in2e/l3candidates.dtx >> Log: >> add \clist_length:N and \clist_nth:N to l3candidates > > >>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. > > 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 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? > > Best wishes, > Will Hello Will, I'm happy with the idea in principal, but not the names or the implementation :-) On the names, we currently have \tl_elt_count:N, so should really follow the model and have \clist_elt_count:N. On the other hand, I notice that there are various other uses of 'element' in other functions. So perhaps we'd be better having \tl_element_count:N and \clist_element_count:N, and not using 'elt' at all. (We also need :c and :n variants.) For \clist_nth:N, I'd prefer '\clist_element:N'. We don't want 'get' here as that is used in non-expandable assignments (see \prop_get:NnN, etc.). 'nth' is really awkward, I think. On the implementation, there are some things to think about. You've gone for an implementation indexed from 1, which gives an error with 'out of range' cases. In other places we've indexed from 0 (as TeX does for \ifcase), and we need to cover negative numbers. I'd prefer to avoid two loops, and also think that 'out-of-range' values should simply result in an empty value, not an error. Based on that, I'd go for: \cs_new_nopar:Npn \clist_element:Nn #1#2 { \exp_args:No \clist_element:nn {#1} {#2} } \cs_new:Npn \clist_element:nn #1#2 { \int_compare:nNnF {#2} < { 0 } { \clist_element_aux:nw {#2} #1 , \q_recursion_tail \q_recursion_stop } } \cs_new:Npn \clist_element_aux:nw #1#2 , #3 { \int_compare:nNnTF {#1} = { 0 } { \use_i_delimit_by_q_recursion_stop:nw {#2} } { \quark_if_recursion_tail_stop:n {#3} \clist_element_aux:nw { #1 - 1 } #3 } } (The implementation in etextools is indexed from 0, by the way.) We should also provide the same for sequences. They, of course, can include empty values, but I'd think a similar approach would be best. -- Joseph Wright