Type Conversions

Risor provides built-in functions for converting values between types. Each function accepts an optional argument and returns the value converted to the target type. When called with no arguments, the function returns the zero value for that type.

int

Convert a value to a 64-bit integer. Strings are parsed as integers, and floats are truncated.

int("42")       // 42
int(3.9)        // 3
int()           // 0

float

Convert a value to a 64-bit floating-point number.

float("3.14")   // 3.14
float(42)       // 42.0
float()         // 0.0

string

Convert a value to its string representation.

string(42)      // "42"
string(3.14)    // "3.14"
string(true)    // "true"
string([1, 2])  // "[1, 2]"
string()        // ""

bool

Convert a value to a boolean. Empty strings, zero, nil, and empty containers are falsy. Everything else is truthy.

bool(1)         // true
bool(0)         // false
bool("")        // false
bool("hello")   // true
bool([])        // false
bool([1])       // true
bool()          // false

byte

Convert a value to a single byte (an integer in the range 0--255).

byte(65)        // 65
byte()          // 0

bytes

Convert a value to a byte sequence.

bytes("hello")          // byte sequence [104, 101, 108, 108, 111]
bytes([72, 101, 108])   // byte sequence from a list of integers
bytes()                 // empty byte sequence

list

Convert an enumerable value (such as an iterator, map, or string) into a list.

list(range(5))          // [0, 1, 2, 3, 4]
list("abc")             // ["a", "b", "c"]
list({a: 1, b: 2})      // [["a", 1], ["b", 2]]
list()                  // []

This is especially useful for materializing lazy iterators like range or the iterators returned by map methods such as keys(), values(), and entries().


Risor © 2026 Deep Noodle