[Posted to info-tex on 10 Oct 91; see exercise.001] ********************************************************************** *** Exercise 2 (hard): Define an "ifempty" macro that takes one argument and resolves essentially to \iftrue if the argument is empty, and \iffalse otherwise. This is useful for handling arguments given by users to commands defined in a macro package. Plain TeX or LaTeX-style solutions are both acceptable, that is, \ifempty{...}TRUE CASE\else FALSE CASE\fi or \ifempty{...}{TRUE CASE}{FALSE CASE} (In the former case you will need to do something to avoid problems in the situation \iffalse ... \ifempty{...} ... \fi ... \fi; there are different possibilities here, so I will refrain from indicating any particular one.) Use the following test suite to verify the robustness of your solution: \long\def\test#1{\begingroup \toks0{[#1]}% \newlinechar`\/\message{/\the\toks0: % LaTeX-style solution; modify the following line according % to the syntax of your solution. \ifempty{#1}{EMPTY}{NOT empty}% }\endgroup} \test{} \test{ } \test{aabc} \test{-} \test{$} \test{\empty} \test{\endinput} \test{\iftrue a\else b\fi} \test{\else} \test{#} \test{\par} \halign{#\cr\test{&}\cr} \test{\relax} \test{\relax\relax\relax} \expandafter\iffalse\test{x}\fi \test{{}} The two tests on the first line should produce a message "EMPTY" and the remaining ones, "NOT empty". The reason for saying that the second test should return "EMPTY" is that (1) this is the ideal behavior for the applications I've encountered so far; (2) at least one other person working independently arrived before me at a solution essentially identical to mine, including this behavior. The details and credit to the other guy will be given at solution time.