निरंजन
Is this a fast way to build a meta-clist from multiple sub-sequences? We have two conditions.
1. `\g_tmpb_seq` will never have `\q_nil`.
2. All the sequences will have equal number of items, the gaps will be filled with `\q_nil`s.
```
\documentclass{article}
\begin{document}
\ExplSyntaxOn
\seq_new:N \g_tmpc_seq
\seq_new:N \g_tmpd_seq
\seq_new:N \l_tmpc_seq
\seq_new:N \l_tmpd_seq
\seq_gset_split:Nnn \g_tmpa_seq { , } { \q_nil, b, c, d }
\seq_gset_split:Nnn \g_tmpb_seq { , } { e, f, g, h }
\seq_gset_split:Nnn \g_tmpc_seq { , } { i, j, \q_nil, l }
\seq_gset_split:Nnn \g_tmpd_seq { , } { m, n, o, \q_nil }
\clist_map_inline:nn { a, b, c, d } {
\seq_set_eq:cc { l_tmp #1 _seq } { g_tmp #1 _seq }
}
\prg_replicate:nn { \seq_count:N \g_tmpb_seq } {
\seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
\quark_if_nil:VF \l_tmpa_tl {
\tl_put_right:Ne \l_tmpb_tl {
\l_tmpa_tl \c_space_tl
}
}
\seq_pop_left:NN \l_tmpb_seq \l_tmpa_tl
\quark_if_nil:VF \l_tmpa_tl {
\tl_put_right:Ne \l_tmpb_tl {
\l_tmpa_tl \c_space_tl
}
}
\seq_pop_left:NN \l_tmpc_seq \l_tmpa_tl
\quark_if_nil:VF \l_tmpa_tl {
\tl_put_right:Ne \l_tmpb_tl {
\l_tmpa_tl \c_space_tl
}
}
\seq_pop_left:NN \l_tmpd_seq \l_tmpa_tl
\quark_if_nil:VF \l_tmpa_tl {
\tl_put_right:Ne \l_tmpb_tl {
\l_tmpa_tl \c_space_tl
}
}
\clist_put_right:NV \l_tmpa_clist \l_tmpb_tl
\tl_clear:N \l_tmpb_tl
}
\clist_show:N \l_tmpa_clist
\ExplSyntaxOn
\end{document}
```
I created two more sequences on purpose just to eliminate `\seq_map_pairwise_function:NNN`.
Top Answer
frougon
This looks almost okay to me. I would clear `\l_tmpb_tl` before using its value (so, at the beginning of the `\prg_replicate:nn` loop body) because one can't assume in general that it is initially empty. Also, I'd use `\exp_not:V` like this:
```
\tl_put_right:Ne \l_tmpb_tl { \exp_not:V \l_tmpa_tl \c_space_tl }
```
so as to avoid immediate recursive expansion of the item you tested to be non-`\q_nil` (unless you do need such early expansion for the actual application, of course).
Finally, I'm factoring out the repetitive code using `\clist_map_inline:nn { a, b, c, d } { … }`, clearing `\l_tmpa_clist` before use, and setting `\ExplSyntaxOff` rather than `\ExplSyntaxOn` before `\end{document}`. :-)
```
\documentclass{article}
\newcommand*{\test}[1]{#1} % to show that it won't be expanded in the clist
\begin{document}
\ExplSyntaxOn
\seq_new:N \g_tmpc_seq
\seq_new:N \g_tmpd_seq
\seq_new:N \l_tmpc_seq
\seq_new:N \l_tmpd_seq
\seq_gset_split:Nnn \g_tmpa_seq { , } { \q_nil, b, c, d }
\seq_gset_split:Nnn \g_tmpb_seq { , } { e, \test{f}, g, h }
\seq_gset_split:Nnn \g_tmpc_seq { , } { i, j, \q_nil, l }
\seq_gset_split:Nnn \g_tmpd_seq { , } { m, n, o, \q_nil }
\clist_map_inline:nn { a, b, c, d } {
\seq_set_eq:cc { l_tmp #1 _seq } { g_tmp #1 _seq }
}
\clist_clear:N \l_tmpa_clist
\prg_replicate:nn { \seq_count:N \g_tmpb_seq } {
\tl_clear:N \l_tmpb_tl
\clist_map_inline:nn { a, b, c, d } {
\seq_pop_left:cN { l_tmp#1_seq } \l_tmpa_tl
\quark_if_nil:VF \l_tmpa_tl {
\tl_put_right:Ne \l_tmpb_tl { \exp_not:V \l_tmpa_tl \c_space_tl }
}
}
\clist_put_right:NV \l_tmpa_clist \l_tmpb_tl
}
\clist_show:N \l_tmpa_clist
\ExplSyntaxOff
\end{document}
```
==>
```
The comma list \l_tmpa_clist contains the items (without outer braces):
> {e i m}
> {b \test {f} j n}
> {c g o}
> {d h l}.
<recently read> }
l.37 \clist_show:N \l_tmpa_clist
```