Imagine I have two commands defined as
\def\witharg#1{something with #1}
\def\without{something without arg}
and I want to define a new command \mycmd that behaves as \witharg if it's followed by an argument (not necessarily enclosed in braces), and behaves like \without if it is not followed by an argument. In fact, the later case can only be true if \mycmd is followed by the token }. To make things slightly more clear, I want
{\mycmd\token\mycmd}
to expand to something similar to the expansion of
{\witharg{\token}\without}
How can I achieve this?
Note that, in fact, trying to evaluate something like {\witharg} fails with TeX complaining that there is an extra }, i.e. the argument to \witharg is missing.

tex-gutsis a really ugly term to use. Can we usetex-onlyorplain-texinstead? – Will Robertson Aug 3 '10 at 6:07tex-core? – Konrad Rudolph Aug 6 '10 at 9:28