Constants
Sidef implements three kinds of constants: const
, define
and enum
.
const
The common way of declaring constants in Sidef, is by using the const
keyword:
This kind of constants are created dynamically at run-time, but cannot be changed during the execution of the program.
When declared inside a class or a function, the constant is created and initialized dynamically, as illustrated in the following example:
define
This keyword will define a compile-time evaluated constant and will point directly to the object at which it evaluated to.
This type of constants are the most efficient ones.
enum
The enum
keyword will automatically declare and assign a list of constants with ascending numeric values (starting from 0):
Alternatively, we have the possibility for specifying an initial value, which will get incremented after each declaration, by calling the method .inc()
.
Last updated