Variables
Simple declarations
myVar = "some value"; myOtherVar = 12;
Constant variables
A variable which name begins with an upper-case letter is constant; it cannot be changed after its first assignment.
MyVar = 3; MyVar = 2; // ERROR
While the variable is null, its value can be set.
MyVar = null; MyVar = 123; // OK MyVar = 456; // ERROR
Private variables
Private variables are visible only from inside the module where they are created. They are defined by prepending an underscore at the beginning of their names.
_myVar = 12;
A variable can be private and constant at the same time.
_MyVar = 12; _MyVar = 13; // ERROR
Typed variables
A variable can be typed be giving a class name before the variable's name. Then it will not be possible to set a value of any other type in the variable.
Int i = 1; i = "abc"; // ERROR
Scalar values
Null
Undefined variables are equal to null, but this kind-of-value can be set explicitely. It means that the underlying pointer is set to NULL; no method can be called, because null is not an object.
value = null;
Booleans
Two possible values: true or false
valYes = true; valNo = false;
Numbers
Used for integer and floating point numbers. Stored as long double.
value1 = 3; value2 = 4.56;
Character strings
Mutable strings are defined using double quotes. Non-mutable strings are defined using single quotes, and only one instance of each string exists.
str1 = "foo bar"; str2 = 'foo bar';
Arrays
Arrays can be used as lists or as associative arrays.
list1 = [12, 34, 'abcd']; list2 = [0 => 12, 1 => 23, 2 => 'abcd']; // same as previous list3 = [3.14, 'foo' => 'bar', 'you' => 1]; list3[] = 'something'; list3['me'] = 2;
Functions
Functions are first-class citizens, they could be affected to a variable, given as parameter or returned by another function.
compute = function(a, b) { return a + 2 * b; }; result = compute(2, 3); // 8
By keeping the local environment of their creation, functions act naturally as closure.
getClosure = function(a) { return function(b) { return a + b; }; }; f = getClosure(3); res = f(4); // 7