Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt

Use this file to discover all available pages before exploring further.

Intrinsics are functions and values that the CLS runtime makes available in every program without any import statement. They are registered directly into the global environment by the interpreter at startup — some by Intrinsics::desktop_defaults (the node-supplied layer: print, input) and the rest by register_core_intrinsics (always present regardless of the node). If you are embedding CLS with Intrinsics::empty(), the node-level intrinsics (print, input) will not be registered at all — referencing them in a script will throw an undefined-variable error. The core set (toString, int, float, bool, str, len, type, now, exit, sleep, throw) is always present. Command-line arguments (args) are passed as the String[] parameter to main() — they are not a standalone global variable.

Reference

Function / ValueSignatureDescriptionNotes
printprint(...values)Prints all arguments to stdout, separated by spacesCalls __toString on class instances
inputinput() -> StringReads one line from stdinNode-provided; not available when using Intrinsics::empty()
toStringtoString(val) -> StringReturns string representation of valCalls __toString on class instances
intint(val) -> intConverts val to integerParses strings; truncates floats; calls __int
floatfloat(val) -> floatConverts val to floatParses strings; widens ints; calls __float
boolbool(val) -> boolConverts val to boolean (truthiness)Calls __bool on class instances
strstr(val) -> StringAlias for toStringSame behaviour
lenlen(val) -> intLength of an array, tuple, record, string, or object with __lenErrors on other types
typetype(val) -> StringReturns the runtime type name as a stringCalls __type if defined on instance
nownow() -> intReturns the current Unix timestamp in millisecondsUses SystemTime::now()
exitexit(code)Terminates the process with the given exit codeCalls std::process::exit
sleepsleep(ms)Pauses execution for ms milliseconds (blocking)For async delays prefer async.delay(ms)
throwthrow(msg)Raises a RuntimeError with the given messageAborts current execution; caught by try/catch
argsargs: String[]Array of command-line argument strings — passed as the parameter to main()Empty array when no CLI args are given

Examples

print

print("Hello, World!");          # Hello, World!
print("value:", 42, true);       # value: 42 true

input

var name = input();
print("You typed:", name);

toString and str

var n = 3.14;
print(toString(n));   # 3.14
print(str(n));        # 3.14  (alias)

int, float, bool

print(int("42"));       # 42
print(int(3.9));        # 3   (truncates)
print(float(10));       # 10.0
print(float("1.5"));    # 1.5
print(bool(0));         # false
print(bool("hello"));   # true

len

print(len([1, 2, 3]));           # 3
print(len("hello"));             # 5
print(len({ "a": 1, "b": 2 })); # 2

type

print(type(42));       # int
print(type(3.14));     # float
print(type("hi"));     # String
print(type([1, 2]));   # Array
print(type(true));     # bool

now

var start = now();
sleep(100);
var elapsed = now() - start;
print("elapsed ms:", elapsed);

exit

if (errorOccured) {
    exit(1);
};

sleep

print("waiting...");
sleep(500);
print("done");

throw

function divide(a: int, b: int) -> float {
    if (b == 0) {
        throw("division by zero");
    };
    return float(a) / float(b);
};

try {
    divide(10, 0);
} catch (e) {
    print("caught:", e);
};

args

function main(args: String[]) -> int {
    print("arg count:", len(args));
    for each a in (args) {
        print("arg:", a);
    };
    return 0;
};

Magic Method Integration

Several intrinsics are intercepted by the interpreter when called on class instances, delegating to special magic methods defined on the class. This lets your classes integrate seamlessly with the global built-ins.
IntrinsicMagic MethodSignatureBehaviour
print, toString, str__toString() -> StringCalled to produce the string representation
int__int() -> intCalled to produce an integer conversion
float__float() -> floatCalled to produce a float conversion
bool__bool() -> boolCalled to produce a boolean conversion
len__len() -> intCalled to return the logical length
type__type() -> StringCalled to return a custom type name string

Example — all magic methods on one class

class Vector {
    export var x: float = 0.0;
    export var y: float = 0.0;

    function __toString() -> String {
        return "Vector(${me.x}, ${me.y})";
    };

    function __len() -> int {
        return 2;
    };

    function __bool() -> bool {
        return me.x != 0.0 or me.y != 0.0;
    };

    function __type() -> String {
        return "Vector";
    };
};

var v = Vector();
v.x = 3.0;
v.y = 4.0;

print(v);           # Vector(3.0, 4.0)
print(len(v));      # 2
print(bool(v));     # true
print(type(v));     # Vector
If a class does not define __toString, print and toString fall back to the default Value::to_string() representation, which shows the underlying runtime debug format.

Build docs developers (and LLMs) love