Standard Library

Standard Library

Available globally without imports.

Function Description
print(args...)Print to stdout without newline.
println(args...)Print to stdout with newline.
input(prompt)Read input from stdin with prompt.
read()Read line from stdin.
time()Get current time in millis.
sleep(ms)Sleep for milliseconds.
call(methodName, args...)Call a method by name using variable indirection.
setTimeout(delay, methodName, callbacks)Execute a method after a delay in milliseconds (non-blocking).
random()Random double [0.0, 1.0).
randomInt(max)Random integer [0, max).
parseInt(str)Convert string to integer.
parseDouble(str)Convert string to double.
split(str, del)Split string into array.
timestampToDate(ts)Convert timestamp to Date struct.
dateToTimestamp(d)Convert Date struct to timestamp.
printDate(d)Print Date struct (YYYY-MM-DD HH:MM:SS).
formatDate(d, fmt)Format Date struct using pattern.

Dynamic Method Invocation

The call() function allows calling methods by name using String variable indirection:


function greet(name) {
    return "Hello " + name;
}

methodName = "greet";
result = call(methodName, "World");  # Returns "Hello World"
    

Delayed Execution

The setTimeout() function executes a method after a specified delay. Execution is non-blocking and runs in a separate thread.


function delayed() {
    println("Executed after 1 second");
}

setTimeout(1000, "delayed");
    

Date and Time

Fahrenheit provides specific methods for handling dates and times.


# Get current time
t = time();

# Convert to Date struct
d = timestampToDate(t);
println("Year: " + d.year);

# Format date
println(formatDate(d, "yyyy-MM-dd HH:mm"));