How to use functions inside expressions
Currently in Urbi 1.x there is no way to include a function inside an expression. This might sound shocking at first, but the deep reason for this is that Urbi 1.x took the (wrong) road of separating commands and expressions, and since functions can involve commands run in parallel and arbitrarily complex execution trees, it was basically impossible to do it without a hack. Urbi 2.x has unified commands and expressions (actually, everything is an object in Urbi 2.x) and the problem has disappeared. So it won’t be long until this problem is properly fixed.
Still, there is a very easy workaround in Urbi 1.x to include function calls inside expressions, and we describe it here.
Whenever you encounter the need of an expression that includes a call to a function “f”, simply use a temporary variable to store the result of the function call, and replace the function call by that variable:
x = 1 + f(y); // becomes var tmp = f(y) | x = 1 + tmp;
We though about automatizing this inside Urbi 1.x but since we have limited resources we decided to focus our efforts on the next generation (Urbi 2.x) rather that try to fix what can be easily “workarounded” in Urbi 1.
Posted: January 12th, 2008 under Workarounds.
Comments: none