# forarray's \ForEach isn't robust

\ForEach and related commands of forarray package aren't robust. They can't deal with lists whose separators are active (e.g., active comma). Also any trailing space after the list item is retained throughout processing. For example, with

\begingroup
\catcode\,=13
\gdef\x{ {a} , \if , {b} , \fi }
\endgroup
\ForEachX{,}{\typeout{X\unexpanded\expandafter{\thislevelitem}X}}\x


I get

\fe@item@check@next ->\fe@getitem@i {a}
\fe@getitem@i #1,->\fe@setitem@i {#1}
#1<-{a} , \if , {b} , \fi
...
{changing \thislevelitem=\relax}
{into \thislevelitem=\long macro:->{a} , \if , {b} , \fi }


This means that on first grabbing of list item, \thislevelitem is the entire list: ->{a} , \if , {b} , \fi.

Please how do I solve these problems?

Also, it will be less confusing if the following forarray syntax

\begin{enumerate}
\ForEach{;}{
\item This is item No.\ \the\thislevelcount.
\begin{enumerate}
\ForEachSublevel{,}{\item \thislevelitem.}
\end{enumerate}
}{%
This is a nested item, Another nested item ;
{This item is, well, nested}, A final item
}
\end{enumerate}


is made like this

\begin{enumerate}
\ForEach{;}{
\item This is item No.\ \the\thislevelcount.
\begin{enumerate}
\ForEach{,}{\item \thislevelitem.}{<level 2 list>}
\end{enumerate}
}
{<level 1 list>}
\end{enumerate}

-
This seems more a feature request than a real question. \ForEachX asks for the delimiter and doesn't do any sanitization: it's a simple package that does simple loops. –  egreg Jun 22 '12 at 23:15
This may qualify as an answer. –  Ahmed Musa Jun 24 '12 at 5:01
\ForEach doesn't perform any sanitization of its input, which makes it unsuitable for usage in a generic package that may be employed in situations where the delimiter has a different category code (this is a common problem for packages dealing with option lists, as you know well).
The \ForEachX` version does a one level expansion of its third argument. There are more robust ways to process lists with arbitrary delimiters.