5

In the following MCE, I apply to every item stored within the \l_tmpa_clist clist an inline function that displays this item preceded by its index (its position in the list). For this index, an auxiliary integer is manually incremented at each item considered:

\documentclass{article}
\begin{document}
\ExplSyntaxOn
\clist_set:Nn \l_tmpa_clist {Foo,Bar,Baz}
The~ \verb|\l_tmpa_clist|~ list~ has,~ as:
\begin{itemize}
  \clist_map_inline:Nn \l_tmpa_clist {
    \int_incr:N \l_tmpa_int
    \item element~ \# \int_use:N\l_tmpa_int :~ #1
  }
\end{itemize}
\ExplSyntaxOff
\end{document}

My question, not restricted to clists' mapping, is as follows: during *-map_inline, is it possible to access to the index of the considered item without the need to resort an auxiliary integer?

1
  • 3
    I don't know for clist, but seq have \seq_map_indexed_inline:Nn. Commented 14 hours ago

1 Answer 1

6

Not clists, but sequences do.

\documentclass{article}
\begin{document}

\ExplSyntaxOn
\seq_set_from_clist:Nn \l_tmpa_seq {Foo,Bar,Baz}
The~ list~ has,~ as:
\begin{itemize}
  \seq_map_indexed_inline:Nn \l_tmpa_seq {
    \item element~ \# #1:~ #2
  }
\end{itemize}
\ExplSyntaxOff

\end{document}

In the braced argument to \seq_map_indexed_inline:Nn #1 stands for the index and #2 for the item.

6
  • 1
    Is there any reason for *_map_indexed_inline:Nn to be provided only for sequences? \tl_map_indexed_inline:Nn for instance could be useful. Commented 14 hours ago
  • 1
    @DenisBitouzé Sequences are stored with an internal structure that allows doing the task, whereas tls and clists don't. Commented 13 hours ago
  • For speed considerations? Commented 13 hours ago
  • 1
    @DenisBitouzé Because we have to implement it, and that means having a use case - in particular, sequences are more powerful than clists so we tend to offer more functions in the seq module. Commented 13 hours ago
  • @JosephWright Okay but it wouldn't hurt :) And what about e.g. \tl_map_indexed_inline:Nn? Is it worth I open a FR? Commented 13 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.