TeX scope is an overwhelmingly convoluted and opaque subject. It is impossible to tell by sight when a scope starts and ends, and what exactly is being affected by it. Since scope is one of the fundamental building blocks of every programming language, this is one aspect of TeX that, in my opinion, desperately needs an overhaul from the ground up. Does LaTeX3 address this subject?
I was asked:
What do you mean by ”impossible to tell by sight“?
I'm not even talking about pathological examples like
\def\mymac{a}%
\input enigma %redefines \begingroup and \endgroup as \relax
\begingroup%
\def\mymac{b}%
\endgroup%
\mymac%
\bye%
which typesets
b
(Could you tell it by sight?)
I'm talking about normal examples, like the fact that the {...}
in \def<control sequence>{...}
do not imply a grouping, but the {...}
in \output{...}
do imply a grouping, yet the {...}
in \mymacro{...}
don't imply grouping, whereas the {...}
in \loop{...}\repeat
do imply grouping.
I'm talking about the fact that \setbox<number> = ...
is local, but \ht<number> = ...
is global (could you tell it by sight?), and when you create a plain TeX box, the current font will be captured in the box, but the current color won't.
And this is just to give you a taste.
\setbox0=\hbox{A} \begingroup \setbox0=\hbox{g} \showthe\dp0 \dp0=2pt \endgroup \showthe\dp0
(it's set at the group level of the setting of the box).expl3
/LaTeX3 (where the entire point is to provide a higher-level set of interfaces). One can't avoid the fact that the argument to macros, etc. is a balanced text which can also be used for grouping, though in LaTeX3 code we've gone for\group_begin:
/\group_end:
exclusively for the latter.