Next: , Previous: , Up: Reference for Common Language Elements   [Contents]


8.12 Variables

In addition to procedure parameters strings preceeded by a dollar sign ($) can also denote variables. Variables, just like procedure parameters can contain strings or numbers and can be used anywhere where an attribute, entity, marker, block or node name or attribute value is needed. Similar to procedure parameters, you can use the tilde (~) character to prepend or append strings with variables.

One big difference between variables and procedure parameters is that variables can be used outside and independent of procedures. This allows conditional statements (if) to be used outside parameters.

You may want to use variables for two reasons. One is to save typing. A long and often repeated attribute value may be shortened (and potentially replaced everywhere in one go). The second reason is to influence the operation of procedures without needing to pass a lot of parameters.

You can define or set the value of a variable using the set command. The <value> must either be a number or an alphanumeric string - any other string must be enclosed in-between quotation marks.

set $<name> = <value>;
exH0_cshexH0

Note that you can use the set command to change the value of parameters inside a procedure.

Variable definitions honour scoping, thus a variable defined in a scope is not available after the scope has been closed (after the closing brace). It is, however, available in any nested scope. This includes procedures replayed (to any depth). Variable lookup inside procedures happens during replay, thus you can refer to variables inside procedures (even if the variables are defined later in the input file). Any value change made to a variable remains in effect after a scope closure.


Next: File Inclusion, Previous: Procedures, Up: Reference for Common Language Elements   [Contents]