[Posted to info-tex on 5 Dec 91; see answer.004] "*********************************************************************** "*** Exercise 5 (fast): " "Assuming a normal value for \escapechar, " " \string\a " "produces two character tokens. What is the category code of the second? "Write an experiment (as short as possible) to demonstrate the "correctness of your answer. The category of the 'a' token is 12. All tokens produced by \string have category 12, except for space tokens, which have category 10. >>Solution 1 [mine]: \def\answercheck#1#2{\message{#2: \ifcat0#2\else NOT \fi Category 12}} \expandafter\answercheck\string\a \answercheck bb This produces on screen the following message: a: Category 12 b: NOT Category 12 >>EndSolution >>Solution 2 [Peter Schmitt]: \def\test#1#2#3{% \message{\ifcat#2#3 #2 and #3 have the same category code \else #2 and #3 have not the same category code \fi}} \def\Test#1#2#3{% \ifcat#2#3 \message{#2 and #3 have the same category code} \else \message{#2 and #3 have not the same category code} \fi} \catcode\A12 \test 1aA \Test 1aA \expandafter\test\string\a A \expandafter\Test\string\a A +++++++++++++++++++++++++++++++++++ Comment: I have given two essentially equivalent Tests --- \test and \Test. (i) \test is slightly more simple because it contains only one \message command, but I think that \Test is more adequate because it avoids to perform the test inside the \message --- there might be some side effect one is not aware off. (ii) Both tests are not as short as possible --- the \true and \false cases could be much shorter, e.g. a T (for true) and a F (for false) would suffice --- the result could be checked in the dvi-file. (I regard this difference as inessential.) Furthermore, setting the catcode of the model character to 12 could easily be omitted (use some character that is known to be an other character'), but I think it should be included: It makes the test independent of any assumption on the format running. This makes the solution more closed and selfsufficient, and therefore also simpler and more elegant (if I may say so). >>EndSolution