Dodo doc > Variables and Functions > Variables
The dodo language is case sensitive. Variable names always start with a lower case letter. They can contain letters, digits, underscore and apostrophe.
More characters are allowed if the variable name is enclosed in single quotes. Since apostrophe is the same character as single quote, it must be escaped with \'. The first character of the name must be a non-uppercase letter as defined by the Unicode standard.
Normal variable name characters and any character which is not in the ASCII range can be used for the rest. The dash and the underscore characters are equivalent. But the last character as well as the third and fourth characters cannot be dashes or underscores.
A variable declaration starts with keyword "def" or a type name followed by a variable name and an initialisation expression introduced by "=". If a type name is specified, the initialisation expression is optional. In that case the variable takes the default value for this type.
def x = 3.41
def centre = (left + right) / 2
String address_1 = "(empty)"
Once a variable is declared, it can be used and manipulated by passing it as argument to a function. By default a variable is passed by value: the function only sees the value held by the variable, and the function invocation has no effect on the variable itself.
To allow the function to manipulate the variable, it should be passed by reference. This is done in dodo by prefixing the variable name with a dot. Affecting a new value to a variable, in particular, makes use of that notation. The "=" operator can mean either equality testing or affectation depending on the how its first operand is passed, by value or by reference.
apples + oranges
sum(x, 2 * x', 3 * x'')
.velocity = distance / time
choice = "Ok"
Note: by default, only local variables in a function and instance members in a type constructor can be passed by reference.
The dodo type system is based on prototypes. Many language features rely on it.
The value of any variable can be used as prototype, or model, for a new variable. The new variable inherits the characteristics of the prototype but some attributes can take new values.
The "new" keyword creates a new variable based on an existing one. The variable name can be followed by a list of attributes with their new value. The expression can be followed by a block containing declarations.
new prettyHouse(wallColour: yellow, windows: 6)
new apple: def size = medium.
^ 3. Variables and Functions
v 3.2. Constants and Enums