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 p0N9FweT017823 for ; Sun, 23 Jan 2011 10:16:00 +0100 Received: (qmail 23704 invoked by alias); 23 Jan 2011 09:15:52 -0000 Delivered-To: GMX delivery to rainer.schoepf@gmx.net Received: (qmail invoked by alias); 23 Jan 2011 09:15:51 -0000 Received: from relay.uni-heidelberg.de (EHLO relay.uni-heidelberg.de) [129.206.100.212] by mx0.gmx.net (mx092) with SMTP; 23 Jan 2011 10:15:51 +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 p0N9DFBO013730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 23 Jan 2011 10:13:15 +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 p0MN16PC017349; Sun, 23 Jan 2011 10:13:04 +0100 Received: by LISTSERV.UNI-HEIDELBERG.DE (LISTSERV-TCP/IP release 16.0) with spool id 853483 for LATEX-L@LISTSERV.UNI-HEIDELBERG.DE; Sun, 23 Jan 2011 10:13:04 +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 p0N9D4ZS008166 for ; Sun, 23 Jan 2011 10:13:04 +0100 Received: from mail-yi0-f49.google.com (mail-yi0-f49.google.com [209.85.218.49]) by relay.uni-heidelberg.de (8.14.1/8.14.1) with ESMTP id p0N9CwlI013379 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=FAIL) for ; Sun, 23 Jan 2011 10:13:03 +0100 Received: by yib2 with SMTP id 2so1531409yib.22 for ; Sun, 23 Jan 2011 01:12:58 -0800 (PST) Received: by 10.151.149.19 with SMTP id b19mr3047063ybo.288.1295773977462; Sun, 23 Jan 2011 01:12:57 -0800 (PST) Received: from [10.0.1.109] (219-90-161-93.ip.adam.com.au [219.90.161.93]) by mx.google.com with ESMTPS id u10sm1929356yba.13.2011.01.23.01.12.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 23 Jan 2011 01:12:56 -0800 (PST) Content-Type: text/plain; charset=us-ascii References: <201101230906.p0N96bln024353@comedy.dante.de> Mime-Version: 1.0 (Apple Message framework v1081) X-Mailer: Apple Mail (2.1081) X-Spam-Whitelist: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by listserv.uni-heidelberg.de id p0N9D4ZS008167 Message-ID: Date: Sun, 23 Jan 2011 19:42:51 +1030 Reply-To: Mailing list for the LaTeX3 project Sender: Mailing list for the LaTeX3 project From: Will Robertson Subject: \clist_length:N and \clist_nth:N To: LATEX-L@listserv.uni-heidelberg.de 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+4IT8uMLfCAi0H3d389pjI6LmmvOYh+3WHXpV3IIC6Lq ti1Gg==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: 6565 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 > > Modified: trunk/l3in2e/l3candidates.dtx > =================================================================== > --- trunk/l3in2e/l3candidates.dtx 2011-01-23 09:06:32 UTC (rev 2134) > +++ trunk/l3in2e/l3candidates.dtx 2011-01-23 09:06:37 UTC (rev 2135) > @@ -192,6 +192,22 @@ > % > % > % > +% \begin{function}{\clist_length:N / (EXP)} > +% \begin{syntax} > +% "\clist_length:N" > +% \end{syntax} > +% Expands to the number of elements in the . > +% \end{function} > +% > +% \begin{function}{\clist_nth:Nn / (EXP)} > +% \begin{syntax} > +% \clist_nth:Nn \Arg{n} > +% \end{syntax} > +% Expands to the -th element of the . > +% \end{function} > +% > +% > +% > % \end{documentation} > % > % \begin{implementation} > @@ -373,7 +389,48 @@ > % \end{macro} > % > % > +% > +% \begin{macro}{\clist_length:N} > % \begin{macrocode} > +\cs_new:Npn \clist_length:N #1 { > + \int_eval:n { > + 0 \clist_map_function:NN #1 \tl_elt_count_aux:n > + } > +} > +% \end{macrocode} > +% \end{macro} > +% > +% > +% \begin{macro}{\clist_nth:Nn} > +% \begin{macrocode} > +\cs_new:Npn \clist_nth:Nn #1#2 { > + \int_compare:nTF { \clist_length:N #1 < #2 } > + { \ERROR } > + { > + \exp_after:wN \clist_nth_aux:nn \exp_after:wN {#1} #2 > + } > +} > +\cs_new:Npn \clist_nth_aux:nn #1#2 { > + \clist_nth_aux_i:nnnw {1}{#2} #1 , \q_recursion_tail \q_recursion_stop > +} > +\cs_new:Npn \clist_nth_aux_i:nnnw #1#2#3, { > + \quark_if_recursion_tail_stop:n {#3} > + \int_compare:nTF {#1==#2} > + { > + \use_i_delimit_by_q_recursion_stop:nw {#3} > + } > + { > + \clist_nth_aux_i:fnnw { \int_eval:n {#1+1} } {#2} > + } > +} > +\cs_generate_variant:Nn \clist_nth_aux_i:nnnw {f} > +% \end{macrocode} > +% \end{macro} > +% > +% > +% > +% > +% \begin{macrocode} > % > % \end{macrocode} > % > -- Will