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 preceded with a single underscore. 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. Note that the last character or the pair of third and fourth characters cannot be dashes or underscores.
Examples:
acceleration
last_node
lastNode
b'
_ønskeliste
_in-frame
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.
Examples:
def x = 3.41
def centre = (left + right) / 2
String address_1 = "(empty)"
MasterPlan plan
Once a variable is declared, it can be used and manipulated by passing it as argument to an operator or 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 or operator 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.
Examples:
apples + oranges
sum(x, 2 * x', 3 * x'')
.velocity = distance / time
Mix(.fruits, 9)
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.
Examples:
new prettyHouse(wallColour: yellow, windows: 6)
new apple: def size = medium.