-
Notifications
You must be signed in to change notification settings - Fork 0
Values
Values are pieces of data in programming languages. They can be several types in Wi: real, null, bool, string, array, map, function, foreign, object and userdata.
Let's go through each one.
A real number is any number. In Wi's implementation, it uses double-precision floating point format.
0
1234
0.4321
-124
-0.421
3.14159265359
1.0
0xcafebabe
0b01010101null represents nothing - an absence of a value.
nullBool (short for boolean) can store only two values: true or false. They are used to indicate whether a condition is truthy or falsy.
true
falseA string is an immutable array of characters. Once created, you can access its characters via [], but you cannot mutate it.
"Hello World!"
"I love Wi"
"Meow"Accessing characters:
"Hello"[0]; // H
"Hello"[4]; // oConcatenation uses ..:
"Hello" .. " " .. "World"; // Hello World
And is able to work with any type:
1 .. null .. true .. "a string"; // 1nulltruea stringAll string functions in Wi's standard library return a new string - they never modify the original.
An array is a linear collection of data. Items are accessed via [i], where i is the index (0-based).
Arrays can be mutated:
var a = [1, 2, 3];
a[0] = 10; // [10, 2, 3]Or using built-in functions:
var a = [1, 2, 3];
a->add(10); // [1, 2, 3, 10]
a->remove(2); // [1, 3, 10]Accessing an index out of range will cause a runtime error:
var a = [];
a[0];runtime error: array index out of range: 0
--> file.wi:1 in main function
Map is a non-linear collection of key-value pairs. Access values with [key]:
var m = { "x": 10 };
print(m["x"]); // 10
m["y"] = 20;
print(m["y"]); // 20Accessing a key that does not exist will cause a runtime error:
var m = {};
print(m["x"]);runtime error: key error
--> file.wi:1 in main function
They are function, foreign, object, and userdata. They all have their respective page because there's way more to talk about.