have this \newsetter
macro that defines a "setter" macro (for lack of a
better name) and a @-prefixed macro of the same name that holds the value. This is how is supposed to work:
\newsetter\macro
\macro{foo}
\@macro % expands to foo
\macro{bar}
\@macro % expands to bar
And this is the \newsetter
code:
\newcommand\newsetter[1]{%
\@temptokena=\expandafter{\expandafter\@gobble\string #1}%
\expandafter\newcommand\csname @\the\@temptokena\endcsname{}%
\expandafter\newcommand\csname\the\@temptokena\endcsname[1]{%
\expandafter\renewcommand\csname @\the\@temptokena\endcsname{##1}}}%
The problem with this code is that it only works in a particular order:
\newsetter\firstword
\firstword{Hello}
\newsetter\secondword
\secondword{World}
\@firstword\ \@secondword % expands to Hello World
Whereas the following fails:
\newsetter\firstword
\newsetter\secondword
\firstword{Hello}
\secondword{World}
\@firstword\ \@secondword % expands to World, \@firstword is empty
What is wrong here?