latex3/svn-mirror — Issue #54: \tl_item:Nn and \tl_item:nn
Author: blefloch
Created: 2011-11-19 14:58:20+00:00
State: open

I think that `\tl_item` functions would be useful (I came across that when picking random characters from a set, given as a token list). Possible code without much thought:

\cs_new_nopar:Npn \tl_item:Nn { \exp_args:No \tl_item:nn }
\cs_new:Npn \tl_item:nn #1#2
{
\exp_args:Nf \tl_item_aux:nn
{
\int_eval:n
{ \int_compare:nNnT {#2} < \c_zero { \tl_length:n {#1} + } #2 }
}
#1
\q_recursion_tail \q_recursion_stop
}
\cs_new:Npn \tl_item_aux:nn #1#2
{
\quark_if_recursion_tail_stop:n {#2}
\int_compare:nNnTF {#1} = \c_zero
{ \use_i_delimit_by_q_recursion_stop:nw {#2} }
{ \exp_args:Nf \tl_item_aux:nn { \int_eval:n { #1 - 1 } } }
}