Here is a fairly general switch case macro, based on expl3. The syntax is
\switchcondition[<type>]{<input>}[<other>]{<cases>}
where <type> is one among string, token, integer or dimen (default string), <input> is the argument to test against the cases, <other> is what to do if no case is matched, and <cases> is the list of cases in the form
{<case-1>}{<code-1>}
{<case-2>}{<code-2>}
[...]
{<case-n>}{<code-n>}
The macro is, by itself, fully expandable, but of course this feature can be exploited only if <other> and <code-k> are fully expandable for every case.
Here's an example.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\switchcondition}{O{string}mmO{}}
{
\use:c { lyl_#1_switch:nnn } { #2 } { #3 } { #4 }
}
\cs_new:Nn \lyl_string_switch:nnn
{
\str_case:nnF { #1 } { #2 } { #3 }
}
\cs_new:Nn \lyl_token_switch:nnn
{
\tl_case:nnF { #1 } { #2 } { #3 }
}
\cs_new:Nn \lyl_integer_switch:nnn
{
\int_case:nnF { #1 } { #2 } { #3 }
}
\cs_new:Nn \lyl_dimen_switch:nnn
{
\dim_case:nnF { #1 } { #2 } { #3 }
}
\ExplSyntaxOff
\newcommand{\placement}[1]{%
\switchcondition{#1}{
{ul}{\let\position\AtPageUpperLeft}
{ll}{\let\position\AtPageLowerLeft}
{ur}{\let\position\AtPageUpperRight}
{lr}{\let\position\AtPageLowerRight}
}[\let\position\ERROR]%
}
% whatever these should do
\providecommand{\AtPageUpperLeft}{APUL}
\providecommand{\AtPageLowerLeft}{APLL}
\providecommand{\AtPageUpperRight}{APUR}
\providecommand{\AtPageLowerRight}{APLR}
\providecommand{\ERROR}{ERROR}
\newcommand{\foo}[1]{%
\switchcondition[integer]{#1}{
{1}{One}
{20}{Twenty}
{42}{The answer!}
}[Uninteresting number]%
}
\begin{document}
\placement{ul}\texttt{\meaning\position}
\placement{ll}\texttt{\meaning\position}
\placement{ur}\texttt{\meaning\position}
\placement{lr}\texttt{\meaning\position}
\placement{xy}\texttt{\meaning\position}
\foo{1}
\foo{6*7}
\foo{3456}
\end{document}
