Thank you Davide!
1. Can't you use "if"s in symbolic mode, too? isn't it suitable for symbolics?
2. A side question. Is there a possibility for you to differentiate between "stand-alone" mode and "function" mode? Because inside functions, it's often desirable that when the function is declared and optimized, some functions (like this) wouldn't optimize themselves, but return themselves as entered, to only be actually evaluated when the function is used.
To demonstrate, you may try the following (this example only uses in-build SMath functions):
f(a,b):=if UnitsOf(a)=UnitsOf(b)
1
else
0
This function will be cancelled out to f(a;b):=1, because at the optimization stage, the program incorrectly takes current values of a and b, that are unitless at that stage. eval() is unfortunately required here.
I would further suggest that both your cases() and Andrey's UnitsOf() would unconditionally return themselves instead of processing, when used in symbolic optimization.
Or alternatively, when inside a function, a call includes arguments (or their derivatives) that are of course unknown at this stage, SMath should somehow pass to plugins a flag that this argument is undefined, so that plugin function could choose if to return actual result, or return itself (or yet another intermediate variant).