latex-packages/tests/utils/powerset/test.tex

83 lines
1.5 KiB
TeX
Raw Normal View History

2022-01-17 10:27:22 +01:00
\documentclass{article}
\ExplSyntaxOn
\clist_new:N \copied_clist
\seq_new:N \saved_seq
%remove left -> push on stack
% call recursive
% add left to 'extra'
% call recursive
% remove left from 'extra'
% add from stack to left
\cs_generate_variant:Nn \clist_remove_all:Nn { N V }
\cs_new:Npn \clist_use_powerset_aux:Nn #1 #2
{
\clist_if_empty:NTF \copied_clist
{
#2
}
{
\clist_get:NN \copied_clist \l_tmpa_tl % gets first element of copied list into local
\seq_push:NV \saved_seq \l_tmpa_tl % pushes local value onto stack
\clist_pop:NN \copied_clist { \l_tmpa_tl } % removes from copied list
\clist_use_powerset_aux:Nn #1 {#2}
\seq_get:NN \saved_seq \l_tmpa_tl
\clist_put_left:NV #1 \l_tmpa_tl
\clist_use_powerset_aux:Nn #1 {#2}
\seq_get:NN \saved_seq \l_tmpa_tl
\clist_remove_all:NV #1 \l_tmpa_tl
\clist_push:NV \copied_clist \l_tmpa_tl
\seq_pop:NN \saved_seq \l_tmpa_tl
}
}
\cs_new:Npn \clist_use_powerset:Nn #1 #2
{
\clist_set_eq:NN \copied_clist #1
\clist_clear:N #1
\clist_remove_duplicates:N \copied_clist
\clist_use_powerset_aux:Nn #1 {#2}
\clist_set_eq:NN #1 \copied_clist
}
\clist_new:N \test_clist
\tl_set:Nn \test_clist {1,2,3,4,5,6,7,8,9}
\def\foo {
\clist_use_powerset:Nn \test_clist
{
% reached~end:~
% \clist_use:Nn \test_clist {,} \newline
\stepcounter{testval}
}
\test_clist
}
\ExplSyntaxOff
\begin{document}
\newcounter{testval}
\noindent \foo
\thetestval
\end{document}