Built-in Functions

Kode provides 40+ built-in functions for common operations.

I/O Functions

print
Print to stdout
println
Print with newline
input
Read from stdin
kode
print("Hello")
println("World")
let name = input("Enter your name: ")
print("Hello, ${name}!")

Type Conversion

int(x)

Convert to integer

float(x)

Convert to float

str(x)

Convert to string

bool(x)

Convert to boolean

kode
int("42")       // 42
float("3.14")   // 3.14
str(123)        // "123"
bool(1)         // true

Math Functions

abs(x)
pow(x, y)
sqrt(x)
floor(x)
ceil(x)
round(x)
min(a, b)
max(a, b)
random()
kode
abs(-5)         // 5
pow(2, 3)       // 8
sqrt(16)        // 4.0
floor(3.7)      // 3
ceil(3.2)       // 4
round(3.5)      // 4
min(5, 10)      // 5
max(5, 10)      // 10
random()        // 0.0 to 1.0

String Functions

kode
len("hello")                // 5
upper("hello")              // "HELLO"
lower("HELLO")              // "hello"
split("a,b,c", ",")         // ["a", "b", "c"]
join(["a", "b", "c"], ",")  // "a,b,c"
trim("  hello  ")           // "hello"
replace("hello", "l", "r")  // "herro"
starts_with("hello", "he")  // true
ends_with("hello", "lo")    // true
contains("hello", "ell")    // true

Array Functions

kode
let arr = [1, 2, 3, 4, 5]

len(arr)            // 5
push(arr, 6)        // [1, 2, 3, 4, 5, 6]
pop(arr)            // 6 (removes last)
has(arr, 3)         // true
reverse(arr)        // [5, 4, 3, 2, 1]
sort(arr)           // [1, 2, 3, 4, 5]

File I/O

kode
// Read file
let content = readFile("data.txt")
print(content)

// Write file
writeFile("output.txt", "Hello, World!")

// Append to file
appendFile("log.txt", "New entry\n")

Utility Functions

kode
type_of(42)          // "int"
type_of("hello")     // "string"
type_of([1, 2, 3])   // "array"

clock()              // Current timestamp
sleep(1000)          // Sleep 1 second (ms)

assert(1 == 1)       // No-op
assert(1 == 2)       // Runtime error