ESC
Type to search...
S
Soli Docs

Core Functions

I/O operations, type conversion, array/hash manipulation, string functions, and math utilities.

I/O Functions

print(value)

Prints a value to standard output without a newline.

print("Hello")
print(" World")  // Output: Hello World
println(value)

Prints a value to standard output with a newline.

println("Hello World")
println(42)
input(prompt?)

Reads a line of input from the user. Returns the user's input as a String.

let name = input("Enter your name: ")
println("Hello, " + name)

Type Functions

type(value)

Returns the type name of a value as a string.

type(42)        // "int"
type("hello")   // "string"
type([1, 2, 3]) // "array"
type(null)      // "null"
str(value)

Convert a value to a string.

str(42)       // "42"
str(3.14)     // "3.14"
str(true)     // "true"
int(value)

Convert a value to an integer.

int("42")     // 42
int(3.7)      // 3
float(value)

Convert a value to a float.

float("3.14") // 3.14
float(42)     // 42.0
len(value)

Returns the length of a string, array, or hash.

len("hello")      // 5
len([1, 2, 3])    // 3
len({"a": 1})     // 1

Array Functions

push(array, value)

Add an element to the end of an array.

let arr = [1, 2]
push(arr, 3)     // arr is now [1, 2, 3]
pop(array)

Remove and return the last element from an array.

let arr = [1, 2, 3]
let last = pop(arr)  // last is 3, arr is [1, 2]
range(start, end, step?)

Creates an array of numbers from start to end (exclusive).

range(0, 5)      // [0, 1, 2, 3, 4]
range(1, 10, 2)  // [1, 3, 5, 7, 9]
range(5, 0, -1)  // [5, 4, 3, 2, 1]

Hash Functions

keys(hash)

Returns an array of all keys in a hash.

let h = {"name": "Alice", "age": 30}
keys(h)     // ["name", "age"]
values(hash)

Returns an array of all values in a hash.

let h = {"name": "Alice", "age": 30}
values(h)   // ["Alice", 30]
entries(hash)

Returns an array of [key, value] pairs.

let h = {"name": "Alice", "age": 30}
entries(h)  // [["name", "Alice"], ["age", 30]]
has_key(hash, key)

Check if a key exists in a hash.

has_key({"a": 1}, "a")    // true
has_key({"a": 1}, "b")    // false
merge(h1, h2)

Merge two hashes together.

merge({"x": 1}, {"y": 2})     // {"x": 1, "y": 2}

String Functions

split(str, sep)

Split a string by a separator.

split("a,b,c", ",")      // ["a", "b", "c"]
join(arr, sep)

Join array elements with a separator.

join(["a", "b"], "-")    // "a-b"
upcase(str) / downcase(str) / trim(str)

Transform string case and whitespace.

upcase("hello")      // "HELLO"
downcase("HELLO")    // "hello"
trim("  hi  ")       // "hi"
replace(str, from, to)

Replace all occurrences of a substring.

replace("hello world", "world", "soli")  // "hello soli"
html_escape(str) / html_unescape(str) / sanitize_html(str)

HTML encoding and security functions.

html_escape("<script>")     // "&lt;script&gt;"
html_unescape("&lt;p&gt;")  // "<p>"
sanitize_html("<p onclick='x'>") // "<p>"

Math Functions

abs(n) / min(a, b) / max(a, b)

Common math operations.

abs(-5)       // 5
min(3, 7)     // 3
max(3, 7)     // 7
sqrt(n) / pow(base, exp)

Square root and power functions.

sqrt(16)      // 4.0
pow(2, 3)     // 8.0
clock()

Returns the current Unix timestamp as a float with sub-second precision.

let start = clock()
// ... do work ...
let elapsed = clock() - start

File I/O Functions

slurp(path)

Read an entire file into a string.

let content = slurp("config.json")
barf(path, content)

Write content to a file.

barf("output.txt", "Hello, World!")