There was I, procrastinating over some TeX code while I should have been writing my dissertation. The code was working more or less fine (better than the writing, at least), until a mysterious \relax
popped up from nowhere!
At first I though it was something stupid from my end, but when I reduced the code to a bare minimum I realised I had no idea what was going on. I reduced the code to use basically only primitives, so it shouldn't be any coding problem. Here's the guilty code:
\def\useIInnn#1#2#3{#2}
\def\useIInn#1#2{#2}
\detokenize\expandafter{\ifnum0=0\expandafter\useIInnn\fi\useIInn{1}{\BOOM}}
\bye
and its output is (surprisingly, for me):
\relax \fi {1}{\BOOM }
Where did that \relax
come from?
I realise that the test wouldn't result in 0=0
because \ifnum
would continue expanding tokens (as far as I understand, it would make 0=01
and result false; I corrected this in the code :). However the \relax
remains a mystery for me.