summaryrefslogtreecommitdiff
path: root/info/challenges/aro-bend/exercise.002
blob: 4d83cb27e3a3b886deae1ec2a847128aa6048e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[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.