# Nested sequence containing sequences

I am trying to create a nested sequence where each element is a sequence but for some reason it does not compile and exists with an emergency stop.

MWE:

\documentclass{article}

\usepackage{expl3}

\ExplSyntaxOn
\cs_generate_variant:Nn \seq_put_right:Nn {Ne}
\cs_generate_variant:Nn \seq_put_right:Nn {NV}

\seq_new:N \l__outer_seq
\seq_new:N \l__inner_seq
{
\seq_clear:N \l__inner_seq
\seq_put_right:Ne \l__inner_seq {##1}
\seq_put_right:Ne \l__inner_seq {##2}
\seq_put_right:Ne \l__inner_seq {##3}
\seq_put_right:NV \l__outer_seq \l__inner_seq
}
\ExplSyntaxOff

\begin{document}
\section{MWE}
\end{document}


After the call of add{1}{2}{3} the outer sequence contains one element which is a (inner) sequence containing the element 1,2 and 3

Visual: [[1, 2, 3]] - the brackets represent a sequence

• So you want to append to \l__inner_seq the items in \l__outer_seq? Please try and explain what \l__inner_seq is expected to contain at the end of the process. Oct 12, 2021 at 14:38
• @egreg I specified the MWE with more information. I hope this is helpfull,. Oct 12, 2021 at 15:05
• :NV means it takes two arguments so \seq_put_right:NV \l__outer_seq is missing something. Oct 12, 2021 at 15:06
• Sorry, but sequences cannot contain other sequences. They're not something like Perl or Python arrays. Maybe you could explain what's the problem you want to solve. Oct 12, 2021 at 15:06
• @egreg but they could contain a variable that holds a sequence which is perhaps all the OP needs Oct 12, 2021 at 15:08

Your outer sequence can hold a variable holding an inner sequence, so:

The sequence \l__outer_seq contains the items (without outer braces):
>  {\l__inner_seq }.

l.26 \seq_show:N\l__outer_seq

?
The sequence \l__inner_seq contains the items (without outer braces):
>  {1}
>  {2}
>  {3}.

l.28 \seq_map_function:NN \l__outer_seq\seq_show:N

?


This shows the outer sequence then maps over that showing the inner sequence is 1,2,3

\documentclass{article}

\usepackage{expl3}

\ExplSyntaxOn
\cs_generate_variant:Nn \seq_put_right:Nn {Ne}
\cs_generate_variant:Nn \seq_put_right:Nn {NV}

\seq_new:N \l__outer_seq
\seq_new:N \l__inner_seq
{
\seq_clear:N \l__inner_seq
\seq_put_right:Ne \l__inner_seq {#1}
\seq_put_right:Ne \l__inner_seq {#2}
\seq_put_right:Ne \l__inner_seq {#3}
\seq_put_right:Nn \l__outer_seq \l__inner_seq
}
\ExplSyntaxOff

\begin{document}
\section{MWE}

• Thanks a lot! Your post almost solved all my questions. The command call e.g. \add{7}{8}{\textbf{9}} seems not to work if an argument contains a macro. Do you perhaps know a solution to that? Oct 12, 2021 at 16:33
• @Nyanyan I copied you and used :Ne so they are expanded perhaps you want :Nn so you just add the tokens as supplied Oct 12, 2021 at 16:35
• :Nn does not work. Tried to test it all day but no success :( Oct 12, 2021 at 16:52
• :Nn will add the argument not its expansion, If something doesnt work make an example and ask a new question Oct 12, 2021 at 17:07
• You're storing a pointer to the current value of \l__inner_seq, not the value… See tex.stackexchange.com/q/618725/4427 Oct 12, 2021 at 17:17