I have some code that works but stops working when I try to refactor it into a function. Here is a MWE:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\seq_new:N \l_shepi_sub_seq:nnn
\cs_new_protected:Nn \shepi_seq:nnn {
\seq_set_split:Nnn \l_shepi_sub_seq {,} {#3}
\seq_set_map:NNn \l_shepi_sub_seq \l_shepi_sub_seq {\exp_not:n {#2}}
\seq_use:Nn \l_shepi_sub_seq {#1}
}
\NewDocumentCommand \works { m } {
\seq_set_split:Nnn \l_shepi_sub_seq {,} {#1}
\seq_set_map:NNn \l_shepi_sub_seq \l_shepi_sub_seq {\exp_not:n {l}}
\[\begin{array}{\seq_use:Nn \l_shepi_sub_seq {}}
\end{array}\]
}
\NewDocumentCommand \fails { m } {
\[\begin{array}{\shepi_seq:nnn {} {l} {#1}}
\end{array}\]
}
\ExplSyntaxOff
\begin{document}
\works{A, B, C}
\ExplSyntaxOn
\shepi_seq:nnn{}{l}{A, B, C}
\ExplSyntaxOff
%\fails{A, B, C}
\end{document}
Uncommenting the \fails call interrupts the compilation with the following error:
! Undefined control sequence.
<argument> \LaTeX3 error:
A sequence was misused.
l.55 \fails{A, B, C}
As my \shepi_seq:nnn function is used by other parts of my codebase, I'd prefer to leave it as it is, but if changes are required, so be it.
Can someone explain what I did wrong?
Side question: Is it good practice to call \seq_set_map:NNn like I did? (The two first parameters denote the same sequence).