2

The answer to TeX.SX submission Labelling confusion in expl3: (public, private) Vs (global, local) dated May 6, 2016 was accompanied by the code below.

Why does loading expl3 with [check-declarations] produce

!LaTeX error:"kernel/non-declared-variable"
!!The variable \csname\endcsname has not been declared on line …

with reference to the line \tl_gset:cn \c_aloui_constant_tl {Do~not~change~me!}?

\documentclass{article}
%\usepackage{expl3}
\usepackage[check-declarations]{expl3}
\begin{document}
\ExplSyntaxOn
\tl_new:N \g_aloui_global_tl
\tl_new:N \l_aloui_local_tl
\tl_new:N \c_aloui_constant_tl
\tl_gset:cn \c_aloui_constant_tl { Do~not~change~me! }
Constant:~\tl_use:c \c_aloui_constant_tl
\tl_set:Nn \l_aloui_local_tl {     Initial~value~for~local~token~list~variable. }
\tl_gset:Nn \g_aloui_global_tl { Initial~value~for~global~token~list~variable. }
\par
Local:~\l_aloui_local_tl
\par
Global:~\g_aloui_global_tl
\par
\group_begin:
  Start~group.
  \tl_set:Nn \l_aloui_local_tl {     Within~group~value~for~local~token~list~variable. }
  \tl_gset:Nn \g_aloui_global_tl { Global~change~of~value~for~global~token~list~variable. }
  \par
  \hfill
  \begin{minipage}{.8\textwidth}
    Local:~\l_aloui_local_tl
    \par
    Global:~\g_aloui_global_tl
    \par
  \end{minipage}
  \par
  End~group.
  \par
\group_end:
\par
Local:~\l_aloui_local_tl
\par
Global:~\g_aloui_global_tl
\ExplSyntaxOff
\end{document}
moewe
  • 175,683
  • 2
    I assume constants should be declared with \tl_const:Nn and used with \tl_use:N \c_aloui_constant_tl. The :c in function names does not mean constant which makes me think both \tl_gset:cn and \tl_use:c aren't quite correct here. – moewe Sep 20 '18 at 10:45
  • 1
    I noticed you frequently use a c argument type when it isn't really necessary, which happens when the function or variable's name depends on some parameter. Not here. – egreg Sep 20 '18 at 11:19

1 Answers1

6

You have

\tl_new:N \c_aloui_constant_tl

So \c_aloui_constant_tl is empty when you issue

\tl_gset:cn \c_aloui_constant_tl { Do~not~change~me! }

You have \tl_gset:cn, so \c_aloui_constant_tl is used in a c-type conversion to an N-type base. As \c_aloui_constant_tl is empty, TeX tries to use the empty control sequence, which is shows as \csname\endcsname.


Not directly linked, but you should create constant token lists in one go:

\tl_const:Nn \c_aloui_constant_tl { Do~not~change~me! }
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • Oh I did not know you could define an empty control sequence (\csname\endcsname) to be something... – moewe Sep 20 '18 at 10:49
  • 2
    @moewe \expandafter\def\csname\endcsname{whatever you wish} Not that useful, though, because you have to call it like \csname\endcsname or with a backslash at the end of a line under \endlinechar=-1 regime. – egreg Sep 20 '18 at 11:15
  • 2
    @egreg And hope that no-one has done \expandafter\def\csname csname\string\endcsname\endcsname{confusing} to make life 'interesting' :) – Joseph Wright Sep 20 '18 at 11:27