If you are willing to switch from etoolbox
to the more powerful expl3
programming environment, you could do like this:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\newlist}{m}
{
\seq_new:c { g_sumanta_lists_#1_seq }
}
\newlist{myrow} % default
\NewDocumentCommand{\additems}{O{myrow} m}
{
\clist_map_inline:nn { #2 }
{
\seq_gput_right:cn { g_sumanta_lists_#1_seq } { ##1 }
}
}
\NewDocumentCommand{\getitem}{O{myrow} m O{\use:n}}
{
\int_compare:nTF { #2 > \seq_count:c { g_sumanta_lists_#1_seq } }
{
NO ITEM
}
{
#3 { \seq_item:cn { g_sumanta_lists_#1_seq } { #2 } }
}
}
\NewDocumentCommand{\uselist}{O{\use:n}m}
{
\seq_map_inline:cn { g_sumanta_lists_#2_seq } { #1 { ##1 } }
}
\ExplSyntaxOff
\newcommand{\makeitem}[1]{\item $#1$}
\begin{document}
\additems{r,\theta,z,\Gamma}
\additems{\Delta}
\getitem{1}
\getitem{2}[\ensuremath]
\getitem{99}
\begin{itemize}
\uselist[\makeitem]{myrow}
\end{itemize}
\newlist{foo}
\additems[foo]{a,b,c}
\begin{enumerate}
\uselist[\makeitem]{foo}
\end{enumerate}
\end{document}
The optional argument to \additems
is a list name (default myrow
), the mandatory one is a comma separated list of items.
With \getitem
you obtain the item whose number is specified by the mandatory argument; the first optional argument is a list name, the trailing optional argument is a one parameter macro that wraps the item (default is just producing the item). In case the number exceeds the available items, NOITEM
is printed; this could be turned into an error message.
The \uselist
command takes as optional argument a one parameter macro that should wrap the item. The default is just producing the item.

etoolbox
are not random access lists, i.e. you can't extract at once list element like a in C - vector