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
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"
len(value)
Returns the length of a string, array, or hash. Also available as a method: .len, .length, .size are all aliases.
len("hello") # 5
len([1, 2, 3]) # 3
len({"a": 1}) # 1
# Method syntax (all equivalent)
[1, 2, 3].len # 3
[1, 2, 3].length # 3
[1, 2, 3].size # 3
Array Functions
Tip: Most array functions are also available as Array class methods.
Use arr.push(42) instead of push(arr, 42) for a more object-oriented style.
push(array, value) / array.push(value)
Add an element to the end of an array.
let arr = [1, 2]
push(arr, 3) # arr is now [1, 2, 3]
# Or use class method style:
let arr2 = [1, 2]
arr2.push(3) # arr2 is now [1, 2, 3]
pop(array) / array.pop
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]
# Or use class method style:
let arr2 = [1, 2, 3]
let last2 = arr2.pop # last2 is 3, arr2 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]
clear(array | hash) / array.clear / hash.clear
Remove all elements from an array or all entries from a hash.
let arr = [1, 2, 3]
clear(arr) # arr is now []
let h = {"a": 1, "b": 2}
h.clear # h is now {}
Hash Functions
Tip: Most hash functions are also available as Hash class methods.
Use h.keys instead of keys(h) for a more object-oriented style.
keys(hash) / hash.keys
Returns an array of all keys in a hash.
let h = {"name": "Alice", "age": 30}
keys(h) # ["name", "age"]
h.keys # ["name", "age"]
values(hash) / hash.values
Returns an array of all values in a hash.
let h = {"name": "Alice", "age": 30}
values(h) # ["Alice", 30]
h.values # ["Alice", 30]
entries(hash) / hash.entries()
Returns an array of [key, value] pairs.
let h = {"name": "Alice", "age": 30}
entries(h) # [["name", "Alice"], ["age", 30]]
h.entries # [["name", "Alice"], ["age", 30]]
has_key(hash, key) / hash.has_key(key)
Check if a key exists in a hash.
has_key({"a": 1}, "a") # true
has_key({"a": 1}, "b") # false
let h = {"a": 1}; h.has_key("a") # true
merge(h1, h2) / hash.merge(other)
Merge two hashes together. Values from h2 take precedence.
merge({"x": 1}, {"y": 2}) # {"x": 1, "y": 2}
let h1 = {"a": 1}; let h2 = {"a": 2}; h1.merge(h2) # {"a": 2}
from_entries(array)
Create a hash from an array of [key, value] pairs.
from_entries([["a", 1], ["b", 2]]) # {"a": 1, "b": 2}
String Functions
Note: String functions are now primarily available as String class methods.
Use "hello".split(",") instead of split("hello", ",").
str.split(sep)
Split a string by a separator. Returns an array of string parts.
"a,b,c".split(",") # ["a", "b", "c"]
"hello world".split(" ") # ["hello", "world"]
str.contains(sub)
Check if a string contains a substring.
"hello world".contains("world") # true
"hello".contains("xyz") # false
str.starts_with(prefix) / str.ends_with(suffix)
Check if a string starts with a prefix or ends with a suffix.
"hello".starts_with("hell") # true
"hello".ends_with("llo") # true
str.index_of(substr)
Returns the index of the first occurrence of substring, or -1 if not found.
"hello world".index_of("world") # 6
"hello".index_of("xyz") # -1
str.substring(start, end)
Extract a substring from start to end (exclusive).
"hello world".substring(0, 5) # "hello"
"hello world".substring(6, 11) # "world"
str.upcase() / str.downcase() / str.trim()
Transform string case and remove whitespace.
"hello".upcase # "HELLO"
"HELLO".downcase # "hello"
" hi ".trim # "hi"
str.replace(from, to)
Replace all occurrences of a substring.
"hello world".replace("world", "soli") # "hello soli"
str.lpad(width, pad_char?) / str.rpad(width, pad_char?)
Pad a string to reach the specified width.
"hi".lpad(5) # " hi"
"hi".rpad(5) # "hi "
"hi".lpad(5, "0") # "000hi"
String.new(value)
Create a String instance from various value types.
String.new(42) # "42"
String.new(3.14) # "3.14"
String.new(true) # "true"
Math Functions
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
File Class
Static methods for file operations.
File.read(path)
Read file contents as string.
let content = File.read("config.json")
File.write(path, content)
Write content to file.
File.write("output.txt", "Hello!")
File.exists(path)
Check if file exists.
if File.exists("config.json")
File.delete(path)
Delete a file.
File.delete("old.txt")
File.glob(pattern)
Match files using glob pattern (non-recursive).
let files = File.glob("docs/*.md")
File.glob_recursive(pattern)
Match files using glob pattern (recursive).
let files = File.glob_recursive("docs/**/*.md")
File.lines(path)
Read file as array of lines.
let lines = File.lines("data.txt")
File.is_dir(path)
Check if path is a directory.
File.is_file(path)
Check if path is a file.
File.size(path)
Get file size in bytes.
File.modified(path)
Get file modification timestamp (Unix epoch in seconds).
let time = File.modified("config.json")
File.copy(src, dest)
Copy file from source to destination.
File.rename(old, new)
Rename/move a file.
File.append(path, content)
Append content to file.