Given this example code:
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\group_begin:
\char_set_catcode_active:n { `\* }
\cs_new_protected:Npn \foo #1
{
\group_begin:
\char_set_catcode_active:N \
\char_set_lccode:nn { `\* } { `\ }
\tex_lowercase:D { \cs_set:Npn * } { Y }
% \tl_lower_case:n { \cs_set:Npn * } { Y }
#1
\group_end:
}
\group_end:
\ExplSyntaxOff
\begin{document}
\begingroup
\catcode`\ \active
\gdef {X}
\gdef\fooarg{ }
\endgroup
\fooarg
\expandafter\foo\expandafter{\fooarg}
\end{document}
Within the argument of \foo active space characters are re-mapped to a new meaning. To not bring an active space into scope for the whole definition of \foo, the \lowercase trick was used.
There are two issues with this code:
- The relevant line of the trick uses a "do not use" function, namely
\tex_lowercase:D. Is there a more idiomatic way for replacing that whole pattern usingexpl3-only functions? According to the documentation of
\char_set_lccode:nn,\tl_lower_case:nseem to be the "official"\tex_lowercase:Dreplacement function. But when used in the above code it produces an error! Undefined control sequence. <argument> *not only for
*but also for several other characters. Why does this happen?

\char_set_catcode_active:N \line seems quite suspicious – egreg Jun 24 '19 at 08:52\tl_lower_case:nis explicitly documented as being about converting 'text' case: it's not intended for any weird catcode stuff. – Joseph Wright Jun 24 '19 at 09:40