Globals Reference
Functions
Section titled “Functions”array_of
Section titled “array_of”Creates an array of the provided length and initializing each element to its index.
var arr1 = array_of(3); // [0, 1, 2]var arr2 = array_of(3, (i) -> i + 1); // [1, 2, 3]Parameters
Section titled “Parameters”length: Number - The length of the array.
initializer: (Number) -> dyn! optional - An optional function that takes the index as a parameter and sets the element in the array to its return.
Returns
Section titled “Returns”[dyn!] - An array of the specified length where each element is either its index or the result of the initializer function.
array_of_length
Section titled “array_of_length”Creates an array of the provided length.
var arr = array_of_length(3); // [nil, nil, nil]Parameters
Section titled “Parameters”length: Number - The length of the array.
Returns
Section titled “Returns”[dyn?] - An array of the specified length filled with nil values.
assert
Section titled “assert”Asserts the value is truthy. Ends the program if not.
assert(true); // Assertion is true, so nothing happens.assert(false, "This is going to error."); // Assertion is false, the program exits, giving an error using the message if provided.Parameters
Section titled “Parameters”value: dyn! - Any value. Falsy values (0 and nil) cause the program to exit.
message: String? optional - An optional message if the assertion fails.
Returns
Section titled “Returns”nil
Throws
Section titled “Throws”Throws an error if the value is false or nil.
assert_eq
Section titled “assert_eq”Asserts two values are equal. Ends the program if not.
assert_eq(1, 1); // Assertion is true, so nothing happens.assert_eq(1, 0, "This is going to error."); // These values are not equal, so the assertion fails and the program exits.
#### Parameters
value1: `dyn!` - The first value to check for equality.
value2: `dyn!` - The second value to check for equality.
message: `String?` <Badge text="optional" /> - An optional message if the assertion fails.
#### Returns
`nil`
#### Throws
Throws an error if the values are not equal.
### `assert_not_nil`
Asserts if that a value is not `nil`. Useful as a typeguard.
```qlvar value1 = true;assert_not_nil(value1); // Nothing happens because value1 is not nilvar value2 = nil;assert_not_nil(value2); // Assertion is false so this throws, exiting the program.Parameters
Section titled “Parameters”function: dyn! - The value to check for nil.
message: String? optional - An optional message if the assertion fails.
Returns
Section titled “Returns”nil
Throws
Section titled “Throws”Throws an error if the provided function does not throw an error.
assert_throws
Section titled “assert_throws”Asserts a function will throw an error. If no error is thrown, the program exits with an error.
assert_throws(() -> 1 / 0); // Nothing happens as 1 / 0 throws an error.assert_throws(() -> println("Hello World", "This is going to error.")); // This callback will not throw, so the program will exit.Parameters
Section titled “Parameters”function: () -> dyn! - The function to call to check for an error.
message: String? optional - An optional message if the assertion fails.
Returns
Section titled “Returns”nil
Throws
Section titled “Throws”Throws an error if the provided function does not throw an error.
identity
Section titled “identity”An identity function.
var value = identity(1); // 1Parameters
Section titled “Parameters”value: dyn! - Any value.
Returns
Section titled “Returns”dyn! - The value provided in the argument.
Prints a value to the console. All values are implicitly converted to strings.
print("Hello World!"); // prints Hello World!Parameters
Section titled “Parameters”value: dyn! - Any value.
Returns
Section titled “Returns”nil
println
Section titled “println”Prints a value to the console followed by a newline. All values are implicitly converted to strings.
println("Hello World!"); // prints Hello World!\nParameters
Section titled “Parameters”value: dyn! - Any value.
Returns
Section titled “Returns”nil
to_string
Section titled “to_string”Returns the value as a string.
var one_string = to_string(1); // "1"Parameters
Section titled “Parameters”value: dyn! - Any value.
Returns
Section titled “Returns”String - The value as a string.
typeof
Section titled “typeof”Returns the type as a string.
println(typeof("Hello World!")); // stringParameters
Section titled “Parameters”value: dyn! - Any value.
Returns
Section titled “Returns”String - a value of "nil", "boolean", "number", "string", "function", "class", "object", "array" or "module" depending on the type of the value.
system_time
Section titled “system_time”Returns the time in milliseconds since the start of the Unix epoch.
var start = system_time();complex_operation();var end = system_time();var duration = start - end; // The time in milliseconds between start and end.Parameters
Section titled “Parameters”None
Returns
Section titled “Returns”Number - The time in milliseconds since the start of the Unix epoch.
Constants
Section titled “Constants”a constant containing the string "array", used with the typeof function can return the runtime type.
assert([] is ARRAY);assert_eq(typeof([]), ARRAY);BOOLEAN
Section titled “BOOLEAN”a constant containing the string "boolean", used with the typeof function can return the runtime type.
assert(true is BOOLEAN);assert_eq(typeof(false), BOOLEAN);a constant containing the string "class", used with the is operator or typeof function can return the runtime type.
class MyClass { }assert(MyClass is CLASS);assert_eq(typeof(MyClass), CLASS);FUNCTION
Section titled “FUNCTION”a constant containing the string "function", used with the is operator or used with the typeof function can return the runtime type.
assert(() -> nil is FUNCTION);assert_eq(typeof(() -> nil), FUNCTION);MODULE
Section titled “MODULE”a constant containing the string "module", used with the is operator or used with the typeof function can return the runtime type.
mod utils = import("./utils.ql");assert(utils is MODULE);assert_eq(typeof(utils), MODULE);a constant containing the string "nil", used with the is operator or used with the typeof function can return the runtime type.
assert(nil is NIL);assert_eq(typeof(nil), NIL);NUMBER
Section titled “NUMBER”a constant containing the string "number", used with the is operator or used with the typeof function can return the runtime type.
assert(0 is NUMBER);assert_eq(typeof(1), NUMBER);OBJECT
Section titled “OBJECT”a constant containing the string "object", used with the is operator or used with the typeof function can return the runtime type.
assert({{ }} is OBJECT);class MyClass { }assert(MyClass() is OBJECT);assert_eq(typeof(MyClass()), OBJECT);STRING
Section titled “STRING”a constant containing the string "string", used with the is operator or used with the typeof function can return the runtime type.
assert("" is STRING);assert_eq(typeof(""), STRING);