I defined two macros \newfoo{#1}{#2} and \foo{#1}. The first parameter is used as a key and must be a valid LaTeX macro name (without the backslash). The second parameter is a short piece of text. Using \newfoo a key is associated with its text and using \foo the text is supposed to be printed, given the previously defined key.
For those familiar with the glossary/-ies package, the commands can best be depicted as a poor-man's version of those, but I need them in other context.
Internally, \newfoo{#1}{#2} defines a macro \foo@#1 and \foo{#1} expands to \foo@#1. The MWE below works. But I would have expected to get a compile error, if \foo is called for a key that has not been defined previously, because \foo@#1 does not exist. However, compilation proceeds silently and simply expands a non-existing \foo@#1 into nothing. This behavior is undesired, because misspelled keys should be noted.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\makeatletter
\newcommand*\newfoo[2]{%
\expandafter\newcommand\csname foo@#1\endcsname{#2}%
}
\newcommand*\foo[1]{\csname foo@#1\endcsname}
\makeatother
\newfoo{a}{1st letter of alphabet}
\newfoo{b}{2nd letter of alphabet}
\begin{document}
\verb#\foo{a}# is expected to expand to ``\foo{a}''
\verb#\foo{b}# is expected to expand to ``\foo{b}''
\verb#\foo{c}# has not been defined by \verb#\newfoo{c}{...}# and should raise a compile error
\end{document}