summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/expl3/l3candidates.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3candidates.dtx')
-rw-r--r--Master/texmf-dist/source/latex/expl3/l3candidates.dtx156
1 files changed, 84 insertions, 72 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3candidates.dtx b/Master/texmf-dist/source/latex/expl3/l3candidates.dtx
index 98b6fdd6aff..4062f8828c6 100644
--- a/Master/texmf-dist/source/latex/expl3/l3candidates.dtx
+++ b/Master/texmf-dist/source/latex/expl3/l3candidates.dtx
@@ -37,7 +37,7 @@
%</driver|package>
%\fi
\errorcontextlines=999
-\GetIdInfo$Id: l3candidates.dtx 2063 2010-10-03 08:26:49Z mittelba $
+\GetIdInfo$Id: l3candidates.dtx 2137 2011-01-23 23:13:58Z will $
{L3 Experimental 'extras' module}
%\iffalse
%<*driver>
@@ -116,35 +116,6 @@
% \end{function}
%
%
-% \begin{function}{\tl_transform:nn|\char_transform:NN}
-% \begin{syntax}
-% |\tl_transform:nn| \Arg{tranformation rules} \Arg{token list}
-% "\char_transform:NN" <char.\ token1> <char.\ token2>
-% \end{syntax}
-% Tokenises and evaluates <token list> according to the transformation rules
-% given in the first argument.
-% These transformation rules may be function/variable
-% redefinitions, catcode changes (see "\char_make_other:N" and so on), or
-% token transformations given by "\char_transform:NN".
-%
-% "\char_transform:NN" declares that within the <token list> argument,
-% any occurences of <token1> are interpreted as if they were <token2> albeit
-% with the same catcode as <token1>.
-%
-% Note 1: Everything evaluated by this function occurs within a group;
-% global definitions will be necessary to make changes outside of it.
-%
-% Note 2: Because this function must be invoked before its arguments are
-% tokenised, it cannot be evaluated within another macro (unless clever use
-% of "\tl_rescan:nn" is employed).
-% \begin{texnote}
-% This is a wrapper around \TeX's "\lowercase" primitive and only the ASCII
-% uppercase letters are protected from being transformed themselves.
-% If you are using Xe\TeX\ or Lua\TeX, be careful of unicode letters that will
-% be affected by this process.
-% \end{texnote}
-% \end{function}
-%
% \section{Functions for sequences}
%
%
@@ -221,6 +192,27 @@
%
%
%
+% \begin{function}{\clist_length:N / (EXP)|\clist_length:n / (EXP)}
+% \begin{syntax}
+% "\clist_length:N" <clist>
+% \end{syntax}
+% Expands to the number of elements in the <clist>.
+% \end{function}
+%
+% \begin{function}{\clist_element:Nn / (EXP)|\clist_element:nn / (EXP)}
+% \begin{syntax}
+% "\clist_element:Nn" <clist> \Arg{i}
+% "\clist_element:nn" |{| <c0>|,| <c1>|,|\dots|,| <c$_{n-\1}$>|,| <c$_n$> |}| \Arg{i}
+% "\clist_element:nn" |{| <c$_{-n-\1}$>|,| <c$_{-n}$>|,|\dots|,| <c$_{-\2}$>|,| <c$_{-\1}$> |}| \Arg{i}
+% \end{syntax}
+% Expands to <c$_i$>, the <i>-th element of the <clist>.
+% The indexing counts from zero, and negative indices count from the end.
+% (Negative indexing is slightly less efficent since the length of the list
+% must first be calculated.)
+% \end{function}
+%
+%
+%
% \end{documentation}
%
% \begin{implementation}
@@ -288,48 +280,6 @@
%
%
%
-% \begin{macro}{\tl_transform:nn,\char_transform:NN}
-% \begin{macrocode}
-\cs_new:Npn \tl_transform:nn #1
- {
- \group_begin:
- \tl_map_function:nN
- { \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z }
- \char_protect_uppercase:N
- \cs_set_eq:NN \char_transform:NN \char_transform_hidden:NN
- #1
- \tl_transform_aux:n
- }
-% \end{macrocode}
-% Allow for catcode changes:
-% \begin{macrocode}
-\cs_new:Npn \tl_transform_aux:n #1
- {
- \tl_to_lowercase:n { \group_end: #1 }
- }
-\cs_set:Npn \char_protect_uppercase:N #1
- {
- \char_set_lccode:nn {`#1} {`#1}
- }
-% \end{macrocode}
-%
-% \begin{macrocode}
-\cs_new:Npn \char_transform_hidden:NN #1#2
- {
- \char_set_lccode:nn {`#1} {`#2}
- }
-\cs_new:Npn \char_transform:NN
- {
- \msg_error:nn {l3prg} {naked-char-transform}
- }
-\msg_new:nnn {l3prg} {naked-char-transform}
- {
- This command can only appear within the first\\
- argument of \string\tl_transform:nn.
- }
-% \end{macrocode}
-% \end{macro}
-%
%
% \begin{macro}{\seq_mapthread_function:NNN}
% \begin{macrocode}
@@ -444,6 +394,68 @@
% \end{macro}
%
%
+%
+% \begin{macro}{\clist_length:N,\clist_length:n}
+% \begin{macrocode}
+\cs_new:Npn \clist_length:N {
+ \exp_args:No \clist_length:n
+}
+\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_element:Nn,\clist_element:nn}
+% \begin{macrocode}
+\cs_new:Npn \clist_element:Nn #1 {
+ \exp_args:No \clist_element:nn #1
+}
+\cs_new:Npn \clist_element:nn #1#2 {
+% \end{macrocode}
+% When negative indexing is used, calculate the length and subtract.
+% This incurs a minor performance penalty, of course, but it's nothing to
+% worry about.
+% \begin{macrocode}
+ \int_compare:nNnTF {#2} < {0}
+ {
+ \exp_args:Nf \clist_element_aux:nw
+ {\clist_length:n {#1}+#2} #1 , \q_recursion_tail , \q_recursion_stop
+ }
+ {
+ \clist_element_aux:nw {#2} #1 , \q_recursion_tail , \q_recursion_stop
+ }
+% \end{macrocode}
+% Shorter but less readable version of the code block above:
+% \begin{verbatim}
+% \exp_args:Nf \clist_element_aux:nnw
+% { #2 \int_compare:nNnT {#2} < {0} { +\clist_length:n {#1} } }
+% #1 , \q_recursion_tail , \q_recursion_stop
+% \end{verbatim}
+% Note in both cases I've used |\exp_args:Nf| directly, since I'm starting
+% to think that adding too many control sequences is bad for \TeX's
+% performance.
+% \begin{macrocode}
+}
+\cs_new:Npn \clist_element_aux:nw #1#2, {
+ \quark_if_recursion_tail_stop:n {#2}
+ \int_compare:nNnTF {#1} = {0}
+ {
+ \use_i_delimit_by_q_recursion_stop:nw {#2}
+ }
+ {
+ \clist_element_aux:nw {#1-1}
+ }
+}
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}