# Redefine a primitive parameter

I want to redefine a primitive parameter as a macro, and make the macro behaves the same as the primitive parameter in some situations.

\tracingcommands = 1
\the\tracingcommands
\ifnum\tracingcommands > 0 true\fi

\let\oldtracingcommands\tracingcommands
\def\tracingcommands{\afterassignment\temp\count255}
\def\temp{\oldtracingcommands\count255 \domore}
\def\domore{}

\tracingcommands = 1 % success
\the\tracingcommands % failure
\ifnum\tracingcommands > 0 true\fi % failure


In running the above example, the last two lines failed. How could these be resolved?

• If \p is primitive and you say \let\q\p then isn't \q just defined as \p, so that if you then redefine \p, \q will follow? I don't know anything about it, but how else could it work? \q must be defined as something and if \p is irreducible, then \q must surely be defined as \p? – cfr Feb 9 '15 at 2:58
• The failure \the\tracingmacros is because \tracingmacros is no longer what it used to be. Using \the\oldtracingmacros would do the trick. However, could you explain what you want as well since it's not clear from the code snippet? For example, if you wish to redefine primitives, how about doing it inside a group so their meanings are restored upon closure? – Werner Feb 9 '15 at 3:34
• The \the primitive can be followed by internal register, but not by the macro. Respect the primitive syntax and think about your problem from another side. – wipet Feb 9 '15 at 7:48

You can do it, provided you use \the when the command is used in a <number> context.

\let\textracingcommands\tracingcommands
\def\tracingcommands{\tctoks={\tcgobble}\afterassignment\tcdo\textracingcommands}
\def\tcdo{DONE}
\def\tcgobble#1#2#3#4{\the}
\newtoks\tctoks
\tctoks={\tcgobble}

\tracingcommands=3

\the\tracingcommands

\ifnum\the\tracingcommands<2 SMALL\else BIG\fi

\bye


Why you would do this is quite dubious to begin with.