diff options
author | Karl Berry <karl@freefriends.org> | 2014-01-01 22:56:28 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-01-01 22:56:28 +0000 |
commit | 999dd6fa37bd291385b20ccf85f980eccfd2e683 (patch) | |
tree | 0556279ecc60a91218fc66f799180d9b30c6bf4a /Master/texmf-dist/source/latex/l3kernel/l3seq.dtx | |
parent | 612e0aeaa3a96eceef8eb6e8de16fac2d6b4d8f0 (diff) |
l3 (1jan14)
git-svn-id: svn://tug.org/texlive/trunk@32537 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3seq.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3seq.dtx | 182 |
1 files changed, 79 insertions, 103 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3seq.dtx b/Master/texmf-dist/source/latex/l3kernel/l3seq.dtx index a697739d8da..ef713afaa31 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3seq.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3seq.dtx @@ -35,7 +35,7 @@ % %<*driver|package> \RequirePackage{l3bootstrap} -\GetIdInfo$Id: l3seq.dtx 4581 2013-07-28 08:38:50Z joseph $ +\GetIdInfo$Id: l3seq.dtx 4623 2013-12-14 13:53:40Z bruno $ {L3 Sequences and stacks} %</driver|package> %<*driver> @@ -777,8 +777,8 @@ % % A sequence is a control sequence whose top-level expansion is of the % form \enquote{\cs{s_@@} \cs{@@_item:n} \marg{item_1} \ldots -% \cs{@@_item:n} \marg{item_n} \cs{s_obj_end}}, with a leading scan -% mark, $n$~items of the same form, and a trailing scan mark. An +% \cs{@@_item:n} \marg{item_n}}, with a leading scan +% mark followed by $n$~items of the same form. An % earlier implementation used the structure \enquote{\cs{seq_elt:w} % \meta{item_1} \cs{seq_elt_end:} \ldots \cs{seq_elt:w} \meta{item_n} % \cs{seq_elt_end:}}. This allowed rapid searching using a delimited @@ -810,10 +810,17 @@ % \end{macrocode} % \end{variable} % +% \begin{macro}[aux]{\@@_tmp:w} +% Scratch function for internal use. +% \begin{macrocode} +\cs_new_eq:NN \@@_tmp:w ? +% \end{macrocode} +% \end{macro} +% % \begin{variable}{\c_empty_seq} % A sequence with no item, following the structure mentioned above. % \begin{macrocode} -\tl_const:Nn \c_empty_seq { \s_@@ \s_obj_end } +\tl_const:Nn \c_empty_seq { \s_@@ } % \end{macrocode} % \end{variable} % @@ -940,7 +947,7 @@ } \tl_set:Nx \l_@@_internal_a_tl { \l_@@_internal_a_tl } } - #1 #2 { \s_@@ \l_@@_internal_a_tl \s_obj_end } + #1 #2 { \s_@@ \l_@@_internal_a_tl } } \cs_new:Npn \@@_set_split_auxi:w #1 \@@_set_split_end: { @@ -961,25 +968,19 @@ % \UnitTested % \begin{macro}{\seq_gconcat:NNN, \seq_gconcat:ccc} % \UnitTested -% \begin{macro}[aux,EXP]{\@@_concat:NN, \@@_concat:w} -% When concatenating sequences, one must take care of the trailing -% \cs{s_obj_end} and leading \cs{s_@@}. The second argument of -% \cs{@@_concat:NN} is \cs{s_@@}, and \cs{@@_concat:w} removes -% \cs{s_obj_end} by a delimited approach. The result starts with -% \cs{s_@@} (of the first sequence), which stops \texttt{f}-expansion. +% When concatenating sequences, one must remove the leading \cs{s_@@} +% of the second sequence. The result starts with \cs{s_@@} (of the +% first sequence), which stops \texttt{f}-expansion. % \begin{macrocode} \cs_new_protected:Npn \seq_concat:NNN #1#2#3 - { \tl_set:Nf #1 { \exp_last_unbraced:NNo \@@_concat:NN #2 #3 } } + { \tl_set:Nf #1 { \exp_after:wN \use_i:nn \exp_after:wN #2 #3 } } \cs_new_protected:Npn \seq_gconcat:NNN #1#2#3 - { \tl_gset:Nf #1 { \exp_last_unbraced:NNo \@@_concat:NN #2 #3 } } -\cs_new:Npn \@@_concat:NN #1#2 { \exp_after:wN \@@_concat:w #1 } -\cs_new:Npn \@@_concat:w #1 \s_obj_end {#1} + { \tl_gset:Nf #1 { \exp_after:wN \use_i:nn \exp_after:wN #2 #3 } } \cs_generate_variant:Nn \seq_concat:NNN { ccc } \cs_generate_variant:Nn \seq_gconcat:NNN { ccc } % \end{macrocode} % \end{macro} % \end{macro} -% \end{macro} % % \begin{macro}[pTF]{\seq_if_exist:N, \seq_if_exist:c} % Copies of the \texttt{cs} functions defined in \pkg{l3basics}. @@ -1035,41 +1036,28 @@ % \end{macro} % \end{macro} % -% \begin{macro}{ -% \seq_put_right:Nn, \seq_put_right:NV, \seq_put_right:Nv, -% \seq_put_right:No, \seq_put_right:Nx, -% \seq_put_right:cn, \seq_put_right:cV, \seq_put_right:cv, -% \seq_put_right:co, \seq_put_right:cx -% } +% \begin{macro} +% { +% \seq_put_right:Nn, \seq_put_right:NV, \seq_put_right:Nv, +% \seq_put_right:No, \seq_put_right:Nx, +% \seq_put_right:cn, \seq_put_right:cV, \seq_put_right:cv, +% \seq_put_right:co, \seq_put_right:cx +% } % \UnitTested -% \begin{macro}{ -% \seq_gput_right:Nn, \seq_gput_right:NV, \seq_gput_right:Nv, -% \seq_gput_right:No, \seq_gput_right:Nx, -% \seq_gput_right:cn, \seq_gput_right:cV,\seq_gput_right:cv, -% \seq_gput_right:co, \seq_gput_right:cx -% } -% \begin{macro}[aux,EXP]{\@@_put_right_aux:w} -% When adding to the right of a sequence, remove \cs{s_obj_end}. This -% is done by \cs{@@_put_right_aux:w}, which takes its result through -% \cs{exp_not:n}. +% \begin{macro} +% { +% \seq_gput_right:Nn, \seq_gput_right:NV, \seq_gput_right:Nv, +% \seq_gput_right:No, \seq_gput_right:Nx, +% \seq_gput_right:cn, \seq_gput_right:cV, \seq_gput_right:cv, +% \seq_gput_right:co, \seq_gput_right:cx +% } +% Since there is no trailing marker, adding an item to the right of a +% sequence simply means wrapping it in \cs{@@_item:n}. % \begin{macrocode} \cs_new_protected:Npn \seq_put_right:Nn #1#2 - { - \tl_set:Nx #1 - { - \exp_after:wN \@@_put_right_aux:w #1 - \exp_not:n { \@@_item:n {#2} \s_obj_end } - } - } + { \tl_put_right:Nn #1 { \@@_item:n {#2} } } \cs_new_protected:Npn \seq_gput_right:Nn #1#2 - { - \tl_gset:Nx #1 - { - \exp_after:wN \@@_put_right_aux:w #1 - \exp_not:n { \@@_item:n {#2} \s_obj_end } - } - } -\cs_new:Npn \@@_put_right_aux:w #1 \s_obj_end { \exp_not:n {#1} } + { \tl_gput_right:Nn #1 { \@@_item:n {#2} } } \cs_generate_variant:Nn \seq_gput_right:Nn { NV , Nv , No , Nx } \cs_generate_variant:Nn \seq_gput_right:Nn { c , cV , cv , co , cx } \cs_generate_variant:Nn \seq_put_right:Nn { NV , Nv , No , Nx } @@ -1077,7 +1065,6 @@ % \end{macrocode} % \end{macro} % \end{macro} -% \end{macro} % % \subsection{Modifying sequences} % @@ -1132,7 +1119,7 @@ % The idea of the code here is to avoid a relatively expensive addition of % items one at a time to an intermediate sequence. % The approach taken is therefore similar to -% that in \cs{@@_pop_right_aux:NNN}, using a \enquote{flexible} +% that in \cs{@@_pop_right:NNN}, using a \enquote{flexible} % \texttt{x}-type expansion to do most of the work. As \cs{tl_if_eq:nnT} % is not expandable, a two-part strategy is needed. First, the % \texttt{x}-type expansion uses \cs{str_if_eq:nnT} to find potential @@ -1322,27 +1309,24 @@ % % \begin{macro}{\seq_get_right:NN, \seq_get_right:cN} % \UnitTested -% \begin{macro}[aux]{\@@_get_right_setup:wN, \@@_get_right_loop:nn} -% First prepend \cs{q_no_value}, then take two arguments at a time. -% Apart from the right-hand end of the sequence, this be a brace group -% followed by \cs{@@_item:n}. The \cs{use_none:nn} removes both of -% those. At the end of the sequence, the two question marks are taken -% by \cs{use_none:nn}, and the assignment is placed before the -% right-most item. The \tn{afterassignment} primitive places -% \cs{use_none:n} to get rid of a trailing \cs{@@_get_right_loop:nn}. +% \begin{macro}[aux]{\@@_get_right_loop:nn} +% First remove \cs{s_@@} and prepend \cs{q_no_value}, then take two +% arguments at a time. Before the right-hand end of the sequence, +% this is a brace group followed by \cs{@@_item:n}, both removed by +% \cs{use_none:nn}. At the end of the sequence, the two question +% marks are taken by \cs{use_none:nn}, and the assignment is placed +% before the right-most item. In the next iteration, +% \cs{@@_get_right_loop:nn} receives two empty arguments, and +% \cs{use_none:nn} stops the loop. % \begin{macrocode} \cs_new_protected:Npn \seq_get_right:NN #1#2 - { \exp_after:wN \@@_get_right_setup:wN #1 #2 } -\cs_new_protected:Npn \@@_get_right_setup:wN \s_@@ #1 \s_obj_end #2 { - \@@_get_right_loop:nn - \q_no_value + \exp_after:wN \use_i_ii:nnn + \exp_after:wN \@@_get_right_loop:nn + \exp_after:wN \q_no_value #1 - { - ?? - \tex_afterassignment:D \use_none:n - \tl_set:Nn #2 - } + { ?? \tl_set:Nn #2 } + { } { } } \cs_new_protected:Npn \@@_get_right_loop:nn #1#2 { @@ -1358,8 +1342,7 @@ % \UnitTested % \begin{macro}{\seq_gpop_right:NN, \seq_gpop_right:cN} % \UnitTested -% \begin{macro}[aux]{\@@_pop_right_aux:NNN, \@@_pop_right_loop:nn} -% \begin{macro}[aux, EXP]{\@@_pop_right_setup:w} +% \begin{macro}[aux]{\@@_pop_right:NNN, \@@_pop_right_loop:nn} % The approach to popping from the right is a bit more involved, but does % use some of the same ideas as getting from the right. What is needed is a % \enquote{flexible length} way to set a token list variable. This is @@ -1368,34 +1351,33 @@ % expansion and a \enquote{non-expanding} definition for \cs{@@_item:n}, % the left-most $n - 1$ entries in a sequence of $n$ items will be stored % back in the sequence. That needs a loop of unknown length, hence using the -% strange \cs{if_false:} way of including brackets. When the last item -% of the sequence is reached, the closing bracket for the assignment is +% strange \cs{if_false:} way of including braces. When the last item +% of the sequence is reached, the closing brace for the assignment is % inserted, and |\tl_set:Nn #3| is inserted in front of the final -% entry. This therefore does the pop assignment. The trailing -% looping macro is removed by placing a \cs{use_none:n} using the -% \tn{afterassignment} primitive. +% entry. This therefore does the pop assignment. One more iteration +% is performed, with an empty argument and \cs{use_none:nn}, which +% finally stops the loop. % \begin{macrocode} \cs_new_protected_nopar:Npn \seq_pop_right:NN - { \@@_pop:NNNN \@@_pop_right_aux:NNN \tl_set:Nx } + { \@@_pop:NNNN \@@_pop_right:NNN \tl_set:Nx } \cs_new_protected_nopar:Npn \seq_gpop_right:NN - { \@@_pop:NNNN \@@_pop_right_aux:NNN \tl_gset:Nx } -\cs_new_protected:Npn \@@_pop_right_aux:NNN #1#2#3 + { \@@_pop:NNNN \@@_pop_right:NNN \tl_gset:Nx } +\cs_new_protected:Npn \@@_pop_right:NNN #1#2#3 { - \cs_set_eq:NN \seq_tmp:w \@@_item:n + \cs_set_eq:NN \@@_tmp:w \@@_item:n \cs_set_eq:NN \@@_item:n \scan_stop: #1 #2 { \if_false: } \fi: \s_@@ - \exp_after:wN \@@_pop_right_setup:w + \exp_after:wN \use_i:nnn + \exp_after:wN \@@_pop_right_loop:nn #2 { - \s_obj_end \if_false: { \fi: } - \tex_afterassignment:D \use_none:n + \if_false: { \fi: } \tl_set:Nx #3 } - \cs_set_eq:NN \@@_item:n \seq_tmp:w + { } \use_none:nn + \cs_set_eq:NN \@@_item:n \@@_tmp:w } -\cs_new:Npn \@@_pop_right_setup:w \s_@@ #1 \s_obj_end - { \exp_after:wN \@@_pop_right_loop:nn \use_none:n #1 } \cs_new:Npn \@@_pop_right_loop:nn #1#2 { #2 { \exp_not:n {#1} } @@ -1407,7 +1389,6 @@ % \end{macro} % \end{macro} % \end{macro} -% \end{macro} % % \begin{macro}[TF]{\seq_get_left:NN, \seq_get_left:cN} % \begin{macro}[TF]{\seq_get_right:NN, \seq_get_right:cN} @@ -1439,9 +1420,9 @@ \prg_new_protected_conditional:Npnn \seq_gpop_left:NN #1#2 { T , F , TF } { \@@_pop_TF:NNNN \@@_pop_left:NNN \tl_gset:Nn #1 #2 } \prg_new_protected_conditional:Npnn \seq_pop_right:NN #1#2 { T , F , TF } - { \@@_pop_TF:NNNN \@@_pop_right_aux:NNN \tl_set:Nx #1 #2 } + { \@@_pop_TF:NNNN \@@_pop_right:NNN \tl_set:Nx #1 #2 } \prg_new_protected_conditional:Npnn \seq_gpop_right:NN #1#2 { T , F , TF } - { \@@_pop_TF:NNNN \@@_pop_right_aux:NNN \tl_gset:Nx #1 #2 } + { \@@_pop_TF:NNNN \@@_pop_right:NNN \tl_gset:Nx #1 #2 } \cs_generate_variant:Nn \seq_pop_left:NNT { c } \cs_generate_variant:Nn \seq_pop_left:NNF { c } \cs_generate_variant:Nn \seq_pop_left:NNTF { c } @@ -1480,7 +1461,7 @@ % % \begin{macro}{\seq_map_function:NN, \seq_map_function:cN} % \UnitTested -% \begin{macro}[aux,rEXP]{\@@_map_function:wN,\@@_map_function:NNn} +% \begin{macro}[aux,rEXP]{\@@_map_function:NNn} % The idea here is to apply the code of |#2| to each item in the % sequence without altering the definition of \cs{@@_item:n}. This % is done as by noting that every odd token in the sequence must be @@ -1489,10 +1470,12 @@ % loop without needing to do a (relatively-expensive) quark test. % \begin{macrocode} \cs_new:Npn \seq_map_function:NN #1#2 - { \exp_after:wN \@@_map_function:wN #1 #2 } -\cs_new:Npn \@@_map_function:wN \s_@@ #1 \s_obj_end #2 { - \@@_map_function:NNn #2 #1 { ? \seq_map_break: } { } + \exp_after:wN \use_i_ii:nnn + \exp_after:wN \@@_map_function:NNn + \exp_after:wN #2 + #1 + { ? \seq_map_break: } { } \__prg_break_point:Nn \seq_map_break: { } } \cs_new:Npn \@@_map_function:NNn #1#2#3 @@ -1605,12 +1588,12 @@ % % \begin{macro}[EXP]{\seq_use:Nnnn, \seq_use:cnnn} % \begin{macro}[EXP, aux] -% {\@@_use:wnwnn, \@@_use_setup:w, \@@_use:nwwwwnwn, \@@_use:nwwn} +% {\@@_use:NNnNnn, \@@_use_setup:w, \@@_use:nwwwwnwn, \@@_use:nwwn} % \begin{macro}[EXP]{\seq_use:Nn, \seq_use:cn} % See \cs{clist_use:Nnnn} for a general explanation. The main % difference is that we use \cs{@@_item:n} as a delimiter rather than % commas. We also need to add \cs{@@_item:n} at various places, and -% \cs{s_@@} and \cs{s_obj_end}. +% \cs{s_@@}. % \begin{macrocode} \cs_new:Npn \seq_use:Nnnn #1#2#3#4 { @@ -1619,12 +1602,8 @@ \int_case:nnF { \seq_count:N #1 } { { 0 } { } - { 1 } - { - \exp_after:wN \@@_use:wnwnn #1 - \@@_item:n { } \s_obj_end { } - } - { 2 } { \exp_after:wN \@@_use:wnwnn #1 {#2} } + { 1 } { \exp_after:wN \@@_use:NNnNnn #1 ? { } { } } + { 2 } { \exp_after:wN \@@_use:NNnNnn #1 {#2} } } { \exp_after:wN \@@_use_setup:w #1 \@@_item:n @@ -1636,11 +1615,8 @@ { \__msg_kernel_expandable_error:nnn { kernel } { bad-variable } {#1} } } \cs_generate_variant:Nn \seq_use:Nnnn { c } -\cs_new:Npn \@@_use:wnwnn - #1 \@@_item:n #2#3 \@@_item:n #4#5 \s_obj_end #6 - { \exp_not:n { #2 #6 #4 } } -\cs_new:Npn \@@_use_setup:w \s_@@ #1 \s_obj_end - { \@@_use:nwwwwnwn { } #1 } +\cs_new:Npn \@@_use:NNnNnn #1#2#3#4#5#6 { \exp_not:n { #3 #6 #5 } } +\cs_new:Npn \@@_use_setup:w \s_@@ { \@@_use:nwwwwnwn { } } \cs_new:Npn \@@_use:nwwwwnwn #1 \@@_item:n #2 \@@_item:n #3 \@@_item:n #4#5 \q_mark #6#7 \q_stop #8 |