Chapter 11

Standard Library

Built-in modules reference

Math Module

import stdlib math as m
Function Description Example
Abs(x) Absolute value m.Abs(-5) → 5
Sqrt(x) Square root m.Sqrt(16) → 4.0
Pow(x, y) x raised to power y m.Pow(2, 10) → 1024
Floor(x) Round down m.Floor(3.7) → 3
Ceil(x) Round up m.Ceil(3.2) → 4
Sin(x) Sine (radians) m.Sin(0) → 0
Cos(x) Cosine (radians) m.Cos(0) → 1
Tan(x) Tangent (radians) m.Tan(0) → 0

Example

import stdlib math as m

// Calculate hypotenuse
a = 3
b = 4
c = m.Sqrt(m.Pow(a, 2) + m.Pow(b, 2))
print("Hypotenuse:", c)  // 5.0

// Trigonometry
angle = 3.14159 / 4  // 45 degrees
print("sin(45°):", m.Sin(angle))
print("cos(45°):", m.Cos(angle))

Time Module

import stdlib time as t
Function Description Returns
clock() High-resolution timer Float (seconds since epoch)
sleep(ms) Pause execution nil
timestamp() Unix timestamp Integer (seconds)
millis() Milliseconds Integer
year() Current year Integer
month() Current month (1-12) Integer
day() Current day (1-31) Integer

Example

import stdlib time as t

// Measure execution time
start = t.clock()

// Do some work
sum = 0
for (i in Range(1, 100001)) {
    sum = sum + i
}

elapsed = t.clock() - start
print("Sum:", sum)
print("Time:", elapsed, "seconds")

// Date/time
print("Current year:", t.year())
print("Current month:", t.month())
print("Current day:", t.day())

// Pause execution
print("Waiting...")
t.sleep(1000)  // 1 second
print("Done!")

IO Module

import stdlib io as io
Function Description
Print(...) Print with newline
Write(...) Print without newline
Input(prompt) Read user input
ReadFile(path) Read file contents
WriteFile(path, content) Write to file
AppendFile(path, content) Append to file
FileExists(path) Check if file exists

Example

import stdlib io as io

// User input
name = io.Input("Enter your name: ")
io.Print("Hello,", name)

// File operations
content = "Hello, File!"
io.WriteFile("test.txt", content)

if (io.FileExists("test.txt")) {
    data = io.ReadFile("test.txt")
    io.Print("File contents:", data)
}

io.AppendFile("test.txt", "\nMore content")

Built-in Functions

These functions are available globally without import:

Function Description Example
print(...) Output to console print("Hello")
len(x) Length of string/array len([1,2,3]) → 3
type(x) Get type name type(42) → "int"
str(x) Convert to string str(42) → "42"
int(x) Convert to integer int("42") → 42
float(x) Convert to float float(42) → 42.0
Range(a, b) Integer range [a, b) Range(0, 5)

JIT & Performance Functions

Function Description
nativeSumLoop(n) JIT sum loop benchmark
nativeFibLoop(n) JIT Fibonacci benchmark
simdInfo() Get SIMD capabilities
simdSumLoop(n) SIMD-accelerated sum
simdDotProduct(n) SIMD dot product
matmulBenchmark(size) Matrix multiply benchmark
reluBenchmark(n) ReLU activation benchmark