[Tex/LaTex] \newcommand and comma separated parameters

comma-separated listmacros

I would like to learn to manipulate comma separated lists in Latex.
To give a concreet but artificial example, I would like to have this command:

\swap{1,10}

expand to this:

{10,1}

How can I achieve it?

Best Answer

I think you should ask what you want in full generality. For your concrete example,

\newcommand*\swap[1]{\doswap#1\relax}
\def\doswap#1,#2\relax{{#2,#1}}

should work, although I didn't test it.