[Solutions for exercises 1,2,3 were originally posted together on 25 Oct 91]
Date: Fri 25 Oct 91 15:19:44-EST
From: Michael Downes
Subject: `Around the bend' #1 solutions
To: info-tex@shsu.edu
Solutions to the exercises of `Around the bend' #1.
"*** Exercise 1 (hard):
"Given arbitrary \b, \c, \d (macros without arguments), for example
"
" \def\b{\c\c} \def\c{*} \def\d{\b\c}
"
"figure out how to define \a so that its replacement text consists
"of \b fully expanded plus \c not expanded plus \d expanded exactly once.
"I.e., with the above definitions the replacement text of \a
"should be
"
" **\c\b\c
"
"You may not use \the or \noexpand in your solution. This is Exercise
"20.16 in the TeXbook, except that there's an added restriction: your
"answer must also not use the \halign ... \span method given in the
"answer to 20.16. (Yes, that means you can't use \valign either!)
The restrictions leave us with (essentially) three expansion-control
commands: \expandafter, \edef and \def.
>>Solution 1 [Peter Schmitt]
\edef\B{\b}
\def\defA#1{\def\defa##1##2{\def\a{#1##2##1}}}
\expandafter\defA\expandafter{\B}
\expandafter\defa\expandafter{\d}{\c}
>>EndSolution
>>Solution 2 [Donald Arseneau]:
\edef\e{\b}
\expandafter \expandafter \expandafter \def\expandafter \expandafter
\expandafter \a\expandafter \expandafter \expandafter {\expandafter
\e\expandafter \c\d}
>>EndSolution
>>Solution 3 [mine]:
\edef\a{\b}
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\a
\expandafter\expandafter\expandafter{\expandafter\a\expandafter\c\d}
>>EndSolution
My solution differed from Arseneau's only in using \a rather than \e
in the first step.
[Solution for exercise 2 moved to answer.002]
[Solution for exercise 3 moved to answer.003]
Michael Downes mjd@math.ams.com (Internet)