Dodo doc > Functions and Variables > Constants and Enums > Constants



Any variable name starting with a lower case letter or enclosed in single quotes can be a constant name. In addition, constant names can start with a single underscore followed by a capital letter then more underscores, capital letters or digits.


Rationale: there is not much distinction between a variable and a constant in dodo, so their names can be the same. The all-capital syntax is intended to ease the translation of C programs to dodo.


A constant is declared like a variable, except that empty brackets "()" are added after the constant name. A constant always requires an initialisation value.


def step() = 4
String filename() = "scores"
Rationale: as a constant is a variable that cannot be assigned a value, it is implemented in dodo as a function without parameters. The compiler can optimise the code to replace the function call with its returned value, or cache the result of the function call if the returned value is unknown.

Use as argument

A constant can be passed by value to a function like any variable. A constant cannot be passed by reference.


2 * pi
Rationale: even though it looks like a variable, this is really a function call for which the brackets are optional. Since the same applies to all functions without parameters, the drawback is that constants cannot be distinguished from no-parameter functions.

Use as prototype

Constants can be used as prototype in exactly the same way as other variables.

^ 3.2. Constants and Enums

v 3.2.2. Enum Values