Qore Programming Language Reference Manual  0.9.1
Constants
Description
Constant definitions allow programmers to refer to values with Qore identifiers rather than using the value or the expression that generates the value.
Constant Declaration Syntax
[public] const [namespace_path::]constant_identifier = initialization_expression;
Example
const PI_SQUARED = pow(Qore::M_PI, 2);

When defining a user module, constant definitions can be preceded by public, which means that the constant will be available (imported) in the Program object importing the module. Note that however the public keyword cannot be used when defining class constants in a public or private declaration block. See public for more information.

Since
0.8.1 The expression used to initialize a constant can be any valid Qore expression as long as no variables are referenced.
Note
  • It is bad programming practice to assign a constant with an expression that has side effects. Furthermore if an expression used to initialize a constant throws an exception, that exception cannot be caught in the program being defined.
  • The order that constants are initialized and assigned does not necessarily correspond to declaration order, however constants may be defined using the values of other constants; if a circular reference is detected a parse exception is raised.
  • Constants are resolved in the second stage of parsing (during the parse commit stage, see also Program::parseCommit()
  • Classes can also declare constants; see Class Constants for more information.