Discovering variables

You can use variables in URBI. Simply assigning a value to x will create a variable x local to your connection:

x = 4;
x;
[00520072] 4.000000

General structure for variables

In URBI kernel 1.0, variable names are always of the form prefix.suffix and when no prefix is supplied, a prefix local to the connection is silently added so that x in one connection will not interfere with x in another connection.

For example, when you type x URBI will in fact use U596851624.x in its memory, with U596851624 being the identifier of your current connection (where you typed x in). In the same way, function calls have a local namespace attributed, so that you can do recursive function calls without interferences. This will be redesigned in URBI 2.0 with advanced name resolution and name space support.

Device values and .val alias

As we already said before, there is one important exception to the rule saying that variables without prefixes are local: when you type headPan, URBI do not treat this as a local variable, but instead it applies an alias that transforms the expression into headPan.val, which is a standard URBI variable containing the device value. So, in reality, headPan do not refers to a local variable but to the global variable headPan.val. Aliases are usually defined in the URBI.INI file.

Making "global" variables

There is no real concept of local or global variable in this version of URBI, as we have explained. Everything is of the form prefix.suffix. Without prefix, the variable is local to the connection but you can use your own prefix to make your variable "global":

myprefix.x = "hello";

Actually, myprefix can be seen, and also defined, as an URBI object, as we will describe it in the chapter "Objects in URBI" which details the object oriented features of URBI.

Expressions

Note that the type of the variable (numeric, string, list or even binary as we will see later) is automatically inferred by URBI.

You can evaluate arbitrary complex expressions, including variables or known functions like sin, cos or random (see the URBI Specification for the full list):

x = pi / 2;
calc << sqrt(1 + sin(x));
[00593076:calc] 1.414214

One interesting feature is that modifiers in complex assignments are constantly reevaluated so that if they contain variables, the value of the modifier might change over time as the corresponding variable is evolving. Consider the following example which assigns to x a sinusoidal oscillation within a sinusoidal envelop between 15 and 25:

the_amplitude = 20 sin:10s ampli:5,
x = 0 sin:2s ampli:the_amplitude,

Complex interactions between variables and devices value can be established with this feature.