Variables🔗
Preview Restrictions
HDevelopEVO does not support global variables yet.
The names of variables are built up by composing letters, digits, and the underscore _.
The type of a variable, iconic or control variable, depends on its position in the parameter list in which the variable identifier is used for the first time, and is determined during the input of the operator parameters.
For more information, see also Basic Types of Parameters.
Whenever a new identifier appears, a new variable with the same identifier is created.
Control and iconic variables must have different names.
The value of a variable is undefined until the first assignment defines it.
Note that the variable has not been instantiated yet.
A read access to an undefined variable leads to a runtime error.
Instantiated variables contain tuples of values.
Depending on the kind of the variable, the data items are either iconic objects or control data.
The length of the tuple is determined dynamically by the performed operation.
A variable can get new values any number of times, but once a value has been assigned, the variable will always keep being instantiated, unless you reset the program execution by clicking .
The content of the variable is deleted before the variable is assigned new values.
Variable Types🔗
The concept of different types of variables allows a first (“coarse”) typification of variables (control or iconic data), whereas the actual type of the data – for example, real
, integer
, string
etc. – is undefined until a concrete value is assigned to the variable.
Therefore, it is possible that the data type of a new data item differs from that of the old one.
In HDevelopEVO, the type of a variable is defined in three different ways:
- procedure parameter definitions (explicitly)
- global variable declarations (explicitly)
- usage in the code (implicitly)
The order of precedence is as follows:
- Procedure parameter definitions
- Global variable declarations
- Usage in the code
In the latter case, the type of a variable is defined by those code lines, where the value of the variable is used and where the exact type of the new value is known before run time.
Within its scope, a variable must always be properly defined. The following type definition errors are possible:
-
A local variable is used, whose type has not been defined before.
⇒ The error ‘The variable never gets initialized’ [21089] is thrown. All lines using the variable become invalid, and the variable is not displayed in the variable window. -
The type of a variable is defined differently, for example, as iconic variable and later as control variable.
⇒ The error ‘The type of the variable could not be determined (conflicting type definitions found)’ [21088] is thrown. All lines using the variable become invalid, and the variable is not displayed in the variable window. -
The type of a variable is properly defined, but used in the wrong context, for example, an iconic variable is used as a control input parameter.
⇒ The error ‘The type of the variable could not be determined (conflicting type definitions found)’ [21088] is thrown. Only the affected code becomes invalid.
Scope of Variables (local or global)🔗
All variables are local by default.
They exist only within their procedure.
Local variables with the same name may exist in different procedures without interfering with each other.
In contrast, global variables may be accessed in the entire program.
They have to be declared explicitly using the global
statement.
This declaration declares a global control variable named File
:
global tuple File
Whereas this declares a global iconic variable Image
.
global object Image
The keyword def
allows you to mark one declaration explicitly as the place where the variable is defined, for example, global def object Image
.
This is only relevant when exporting the program to a programming language.
See the description of the operator global
for more information.
Once the global variable is declared, it can be used just like a local variable inside the procedure it has been declared in.
If you want to access a global variable in a different procedure, you have to announce this by using the same global ...
call (otherwise, a local variable will be created).
Example
main procedure:
* declare global variables
global tuple File
global object Image
...
File := 'particle'
read_image(Image, File)
process_image()
* Image has been changed by process_image()
* File remains unchanged
...
process_image procedure:
* use global variable
global object Image
...
bin_threshold(Image, Region)
File := 'fuse'
read_image(Image, File)
return()
Procedures have to explicitly announce their use of global variables.
Existing procedures cannot be broken by introducing global variables in other parts of the program.
The names of global variables have to be unique in the entire HDevelopEVO program.