# build a capitalized CS from a lowercase string and to give it a definition

Is it possible to build a capitalized Control Sequence from an argument of lowercase string and to give it a definition? I tested two codes, but both didn't work well.

code1:

\def\makecs#1#2{%
\expandafter\def\csname \uppercase{#1}\endcsname{#2}
}
\makecs{macroname}{definition}
\MACRONAME


code2:

\def\makeCS#1#2{%
\expandafter\def\uppercase{\csname #1\endcsname}{#2}
}
\makeCS{macro}{def}
\MACRO


Now I understand why they didn't work well, but I have no ideas for alternative solution. What should I do to build a capitalized Control Sequence from an argument of lowercase string and to give it a definition?

\uppercase is not expandable. Therefore it does not expand inside \csname, which then chokes on \uppercase in the name.

Also \expandafter\def\uppercase cannot expand \uppercase, thus \expandafter has no effect and the remaining \def\uppercase would change the definition of \uppercase.

There \uppercase should be given outside:

\def\makecs#1#2{%
\uppercase{\expandafter\def\csname #1\endcsname}{#2}%
}
\makecs{macroname}{definition}
\MACRONAME


First \uppercase is called, which converts the lowercase tokens in #1 to upper case (the other tokens are command tokens). Then \def is called with the upper case letters in place.

Step by step:

 \makecs{macroname}{definition}
\uppercase{\expandafter\def\csname macroname\endcsname}{definition}
\expandafter\def\csname MACRONAME\endcsname{definition}
\def\MACRONAME{definition}