There are several tools in expl3
that can help in doing some task.
Use \seq_item:Nn
only if you really need to; for doing something to all items in a sequence there are \seq_map_inline:Nn
or \seq_map_function:NN
.
Manuel, in his answer, has already pointed out some of the issues in your code; the main one is that declaration of variables should generally be outside definition of macros/functions.
It's of course possible to declare variables in a function, but do it only when such variables should be defined at runtime, with a name depending on current conditions.
Also you should not use \DeclareDocumentCommand
, in general: this would overwrite any preceding definition of the same macro.
Here's a version with \seq_map_inline:Nn
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\setlist}{m}
{
\seq_gset_from_clist:Nn \g_textnik_test_seq { #1 }
}
\NewDocumentCommand{\getitems}{}
{
\seq_map_inline:Nn \g_textnik_test_seq
{
##1\par
}
}
\seq_new:N \g_textnik_test_seq
\ExplSyntaxOff
\begin{document}
\setlist{line1, line2, line3}
\getitems
\end{document}
You can see that the current item is passed to the mapping part as #1
(here ##1
, because we're in a definition). You can do whatever you want to it, even passing it as the argument to another macro.
The same with \seq_map_function:NN
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\setlist}{m}
{
\seq_gset_from_clist:Nn \g_textnik_test_seq { #1 }
}
\NewDocumentCommand{\getitems}{}
{
\seq_map_function:NN \g_textnik_test_seq \textnik_dopar:n
}
\seq_new:N \g_textnik_test_seq
\cs_new_protected:Nn \textnik_dopar:n
{
#1\par
}
\ExplSyntaxOff
\begin{document}
\setlist{line1, line2, line3}
\getitems
\end{document}
In this case, each item is passed as the argument to the indicated one parameter function.

You can add the counter as well:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\setlist}{m}
{
\seq_gset_from_clist:Nn \g_textnik_test_seq { #1 }
}
\NewDocumentCommand{\getitems}{}
{
\int_zero:N \l_textnik_test_int
\seq_map_inline:Nn \g_textnik_test_seq
{
\int_incr:N \l_textnik_test_int
\int_to_arabic:n {\l_textnik_test_int}:~##1\par
}
}
\seq_new:N \g_textnik_test_seq
\int_new:N \l_textnik_test_int
\ExplSyntaxOff
\begin{document}
\setlist{line1, line2, line3}
\getitems
\end{document}
\seq_map_inline:nn
?