Declarations of constants are introduced using the const
keyword. A value is not necessarily assigned to a value. Three syntactic rules are allowed:
1 const const_id_1 = V; 2 3 const const_id_2 : Dom = V; 4 5 const const_id_3 : Dom;
The first case simply declares a constant const_id_1
with the value V
where V
is any constant expression. The type associated to const_id_1
is the type of V
. The second case permits to declare the domain Dom of the constant const_2
; this is mainly useful for integer variables. In the last case the value of const_id_3
is not given; since no type inference exists in AltaRica a domain must be specified.
The constant value V
used to define a constant can refer to other constants. For instance, the following code defines an integer constant according to a Boolean flag:
1 const LARGE_MODEL : bool = true; 2 3 const SMALL_QUEUE_SIZE = 2; 4 const LARGE_QUEUE_SIZE = 20; 5 6 const QUEUE_SIZE = if LARGE_QUEUE then LARGE_QUEUE_SIZE else SMALL_QUEUE_SIZE; 7 8 domain Queue = bool[QUEUE_SIZE];
Compound constants are specified between braces {}
:
- For arrays, values are simply the elements of the array separated by commas;
- For structures, a list of field assignments separated by commas is given. The field name is prefixed with a dot (
.
).
The following example defines a constant array and a constant structure:
1 const CST_ARRAY = { 1, 2 ,3 }; 2 const CST_STRUCT = { .flag = true, .values = CST_ARRAY };