See the code below, the first two examples are fine while the last gave errors.
The possible reason is that \seq_if_in:NnTF is not expandable.
But I'd like to check the argument and print some error message if the argument is not contained in some sequence, and in the same time, make the command able to be used in \int_eval:n or nested.
Is there some way?
\documentclass{article}
\usepackage{xparse}
\begin{document}
\ExplSyntaxOn
\seq_set_from_clist:Nn \l_tmpa_seq { 1, 2, 3 }
\cs_new:Nn __add_one_or_two:n
{
\seq_if_in:NnTF \l_tmpa_seq { #1 }
{ \int_eval:n { #1 + 1} }
{ \int_eval:n { #1 + 2} }
}
% example 1, fine
__add_one_or_two:n { 3 }
% example 2, fine
__add_one_or_two:n { 4 }
% example 3
\int_eval:n { 2 + __add_one_or_two:n { 5 } }
\ExplSyntaxOff
\end{document}
\seq_map_function:NNto examine one by one the sequence elements and break the loop in case of a hit; add a sentinel as the last item in the sequence to signal you're at the end. – egreg Oct 02 '20 at 09:53