Skip to content

Standard Library & Global Built-ins

This content is for v0.2.1. Switch to the latest version for up-to-date documentation.

RayQuiro includes built-in functions that are globally accessible from any script without needing an import statement.


FunctionSignatureDescription
printprint(...args)Prints arguments separated by space to stdout, followed by a newline.
assertassert(condition, message = "")Throws a runtime error if condition is falsy.
typetype(value)Returns the type name: "number", "string", "bool", "array", "object", "function", or "null".
print("Hello", 42, true);
assert(2 + 2 == 4, "Math error!");
print(type("text"));
print(type([1, 2]));

FunctionSignatureDescription
strstr(value)Converts any value to its string representation (alias: to_string).
to_stringto_string(value)Equivalent to str(value).
numnum(value)Parses a string or boolean into a floating-point number.
boolbool(value)Converts a value into a boolean based on truthiness.
var n = num("3.1415");
var s = str(100);
var b = bool(1);

FunctionSignatureDescription
lenlen(container)Returns the number of characters in a string, elements in an array, or keys in an object.
lengthlength(container)Alias for len(container).
rangerange(stop) / range(start, stop, step = 1)Generates an array of numbers from start to stop (exclusive).
pushpush(array, value)Appends value to the end of array.
poppop(array)Removes and returns the last element of array.
joinjoin(array, separator = "")Concatenates elements of array into a string separated by separator.
splitsplit(str, separator = "")Splits str by separator into an array of substrings.
keyskeys(object)Returns an array of keys belonging to object.
valuesvalues(object)Returns an array of values belonging to object.
mapmap(array, fn)Transforms each element in array using fn(item).
filterfilter(array, fn)Returns elements in array that satisfy predicate fn(item).
reducereduce(array, fn, initial)Reduces array to a single value using accumulator fn(acc, item).
var nums = range(1, 5);
push(nums, 5);
var last = pop(nums);
var doubled = map(nums, fn(x) { return x * 2; });
var evens = filter(nums, fn(x) { return x % 2 == 0; });
var sum = reduce(nums, fn(acc, x) { return acc + x; }, 0);
var words = split("rayquiro is fast", " ");
var sentence = join(words, "-");

RayQuiro includes high-precision mathematical operations accessible directly:

FunctionSignatureDescription
sqrtsqrt(x)Returns the square root of x.
absabs(x)Returns the absolute value of x.
powpow(x, y)Returns x raised to the power of y.
sinsin(rad)Sine of angle in radians.
coscos(rad)Cosine of angle in radians.
tantan(rad)Tangent of angle in radians.
loglog(x)Natural logarithm (base $e$) of x.
floorfloor(x)Largest integer less than or equal to x.
ceilceil(x)Smallest integer greater than or equal to x.
roundround(x)Rounds x to the nearest integer.
minmin(a, b)Returns the lesser of a and b.
maxmax(a, b)Returns the greater of a and b.
clampclamp(x, min, max)Constrains x within [min, max].
pipiMathematical constant $\pi$ ($3.141592653589793$).
print(sqrt(16));
print(pow(2, 8));
print(clamp(15, 0, 10));
print(cos(pi));

FunctionSignatureDescription
sleepsleep(ms)Blocks the current thread for the specified number of milliseconds (also available as time.sleep).
print("Waiting 500ms...");
sleep(500);
print("Done!");