Just like in any other programming language, variables are used to store intermediate data. They are defined using the var keyword and must be instantly assigned a value:

var a = 42
var b = 13.37
var somestr = "hello world"
And so on. The variable type is inferred from the expression that is being assigned to it. Being a statically-typed language, Mirelle binds value types to variables, meaning you cannot assign a string to a value which has once been defined as integer, a floating point or anything else.

Once the variable has been defined, it can be used instead of the constant it holds in expressions and statements:

var hello = "Hello"
var world = "world"
print hello, " ", world

Variable names must be valid identifiers.

Next article: Expressions

Related articles: Visibility scopes, Variable splatting

Last edited Mar 16, 2011 at 10:07 PM by impworks, version 8


No comments yet.