diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /info/challenges/aro-bend/answer.005 |
Initial commit
Diffstat (limited to 'info/challenges/aro-bend/answer.005')
-rw-r--r-- | info/challenges/aro-bend/answer.005 | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/info/challenges/aro-bend/answer.005 b/info/challenges/aro-bend/answer.005 new file mode 100644 index 0000000000..6c82a057af --- /dev/null +++ b/info/challenges/aro-bend/answer.005 @@ -0,0 +1,66 @@ +[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 |