\ifnum and similar constructs sometimes insert \relax tokens. Consider
the following example:
\edef\a{\relax}
\edef\b{\ifnum0=0\fi}
\tt
\meaning\a \par
\meaning\b
\ifx\a\b yes\else no\fi
\bye
Why is \a not equal to \b even though their meanings are apparently
equal?
Thanks in advance,
Philipp
--
Change “LookInSig” to “tcalveu” to answer by mail.
> \ifnum and similar constructs sometimes insert \relax tokens. Consider
> the following example:
>
> \edef\a{\relax}
> \edef\b{\ifnum0=0\fi}
>
> \tt
> \meaning\a \par
> \meaning\b
>
> \ifx\a\b yes\else no\fi
>
> \bye
>
> Why is \a not equal to \b even though their meanings are apparently
> equal?
One is a "frozen \relax", the other is a normal \relax. The frozen
\relax has the a token printed as "\relax" but that is not accessible by
spelling \relax in the input. You can redefine the meaning of a normal
\relax without affecting the frozen one.
Lisp offers something similar called "uninterned symbols". They print
like their interned cousins, but are not eq to them or each other, and
they don't listen if you call their name.
--
David Kastrup
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
> Philipp Stephani <Look...@arcor.de> writes:
>
> > \ifnum and similar constructs sometimes insert \relax tokens. Consider
> > the following example:
> >
> > \edef\a{\relax}
> > \edef\b{\ifnum0=0\fi}
> >
> > \tt
> > \meaning\a \par
> > \meaning\b
> >
> > \ifx\a\b yes\else no\fi
> >
> > \bye
> >
> > Why is \a not equal to \b even though their meanings are apparently
> > equal?
>
> One is a "frozen \relax", the other is a normal \relax. The frozen
> \relax has the a token printed as "\relax" but that is not accessible by
> spelling \relax in the input. You can redefine the meaning of a normal
> \relax without affecting the frozen one.
The two forms of \relax must be different, otherwise something like
\def\relax{0}
\edef\b{\ifnum1=0\fi1...}
might give unexpected results, wouldn't it? Indeed
\edef\RELAX{\ifnum0=0\fi}
\expandafter\def\RELAX{1}
results in "Missing control sequence inserted", which means that
the "frozen \relax" is not valid after \def; on the other hand,
with the original meaning of \relax,
\if\relax\RELAX
is true. So the frozen \relax has character code 256 as far as
\if is concerned (and category code 16 for \ifcat), but is not
admissible after \def. Nice.
Ciao
Enrico
> David Kastrup <d...@gnu.org> wrote:
Thanks for the explanations.
> Enrico Gregorio <greg...@math.unipd.it> writes:
>
> > David Kastrup <d...@gnu.org> wrote:
>
> Thanks for the explanations.
Mine were not really explanations, just a couple of
thoughts about the matter, to understand why there are
"two kinds" of \relax.
Ciao
Enrico
> Philipp Stephani <Look...@arcor.de> writes:
>
>> \ifnum and similar constructs sometimes insert \relax tokens.
>> [...]
>> \edef\b{\ifnum0=0\fi}
[...]
> One is a "frozen \relax",
If the above is written as the more natural (!)
\edef\b{\ifnum0=0 \fi}
then the frozen relax does not appear, and \b becomes empty.
Not putting the space there seems like a violation of good sense, since
\fi encountered while parsing a number ends the reason for parsing the
number in the first place. So I am guessing that the frozen relax is put
there to protect against some bad side effect of this usage. But I can't
quite put my finger on it.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
> + David Kastrup <d...@gnu.org>:
>
>> Philipp Stephani <Look...@arcor.de> writes:
>>
>>> \ifnum and similar constructs sometimes insert \relax tokens.
>>> [...]
>>> \edef\b{\ifnum0=0\fi}
> [...]
>> One is a "frozen \relax",
>
> If the above is written as the more natural (!)
> \edef\b{\ifnum0=0 \fi}
> then the frozen relax does not appear, and \b becomes empty.
>
> Not putting the space there seems like a violation of good sense, since
> \fi encountered while parsing a number ends the reason for parsing the
> number in the first place. So I am guessing that the frozen relax is put
> there to protect against some bad side effect of this usage. But I can't
> quite put my finger on it.
On second thought it makes sense. I'd have to look in the source to be
sure, but I'll bet the expansion of \fi, if encountered in the midst of
parsing a number, is \relax\fi - so that in this case, for example, the
\ifnum can be resolved into false or true before the \fi is encounted
again. It looks like a reasonable way to handle what is otherwise a
mess, the \fi ending an \ifnum that doesn't even know yet which way to
jump.