Version: 0.1.0
Last Updated: December 2024
Complete reference for all 75+ built-in functions in the ProXPL standard library, organized by module with examples and usage notes.
- I/O Functions
- Math Functions
- String Functions
- Collections Functions
- Type Conversion Functions
- System Functions
- DateTime Functions
- Runtime Functions
- Quick Reference
Prints values to the console, separated by spaces.
Signature:
print(...args) -> voidParameters:
...args- One or more values of any type
Returns: void
Examples:
print("Hello, World!");
// Output: Hello, World!
print("Count:", 42, "Active:", true);
// Output: Count: 42 Active: true
let items = [1, 2, 3];
print(items);
// Output: [1, 2, 3]Notes:
- Automatically converts all arguments to strings
- Arrays and objects are formatted as readable output
- null prints as "null"
- Functions print as ""
Reads a line of input from the user with an optional prompt.
Signature:
input(prompt: string) -> stringParameters:
prompt- String to display before reading input
Returns: string - The user's input (without trailing newline)
Examples:
func greet() {
let name = input("What is your name? ");
print("Hello, " + name + "!");
}
greet();
// Output: What is your name? Alice
// Hello, Alice!Notes:
- Displays the prompt before waiting for input
- Automatically removes the trailing newline
- Returns empty string if user enters nothing
Reads the entire contents of a text file.
Signature:
read_file(path: string) -> stringParameters:
path- Path to the file to read
Returns: string - File contents
Examples:
let content = read_file("config.txt");
print(content);
let lines = split(content, "\n");
for (let i = 0; i < len(lines); i = i + 1) {
print(lines[i]);
}Notes:
- Throws error if file doesn't exist or can't be read
- Preserves newlines and special characters
- Read entire file into memory
Writes content to a file, overwriting if it exists.
Signature:
write_file(path: string, content: string) -> boolParameters:
path- Path to the filecontent- Content to write
Returns: bool - true if successful
Examples:
let data = "Hello, File!\nLine 2\n";
if (write_file("output.txt", data)) {
print("File written successfully");
} else {
print("Failed to write file");
}Notes:
- Creates file if it doesn't exist
- Overwrites entire file (use append_file to add)
- Returns false if write fails
Appends content to the end of a file.
Signature:
append_file(path: string, content: string) -> boolParameters:
path- Path to the filecontent- Content to append
Returns: bool - true if successful
Examples:
for (let i = 1; i <= 3; i = i + 1) {
append_file("log.txt", "Log entry " + to_string(i) + "\n");
}Notes:
- Creates file if it doesn't exist
- Appends to existing content
- Returns false if operation fails
Returns the absolute value of a number.
Signature:
abs(n: int|float) -> int|floatParameters:
n- A number
Returns: Same type as input
Examples:
print(abs(5)); // 5
print(abs(-5)); // 5
print(abs(0)); // 0
print(abs(-3.14)); // 3.14Rounds up to the nearest integer.
Signature:
ceil(n: float) -> intParameters:
n- A floating-point number
Returns: int
Examples:
print(ceil(3.1)); // 4
print(ceil(3.9)); // 4
print(ceil(3.0)); // 3
print(ceil(-2.1)); // -2Rounds down to the nearest integer.
Signature:
floor(n: float) -> intParameters:
n- A floating-point number
Returns: int
Examples:
print(floor(3.1)); // 3
print(floor(3.9)); // 3
print(floor(-2.9)); // -3Rounds to the nearest integer or specified decimal places.
Signature:
round(n: float, digits?: int) -> int|floatParameters:
n- A number to rounddigits- Optional: decimal places (default: 0)
Returns: int if no digits, float if digits specified
Examples:
print(round(3.7)); // 4
print(round(3.4)); // 3
print(round(3.14159, 2)); // 3.14
print(round(3.14159, 3)); // 3.142Returns the square root of a number.
Signature:
sqrt(n: number) -> floatParameters:
n- A non-negative number
Returns: float
Examples:
print(sqrt(16)); // 4.0
print(sqrt(2)); // 1.414...
print(sqrt(0)); // 0.0Raises base to the power of exponent.
Signature:
pow(base: number, exp: number) -> numberParameters:
base- The baseexp- The exponent
Returns: number (int if both args are int and exp >= 0)
Examples:
print(pow(2, 3)); // 8
print(pow(2, 10)); // 1024
print(pow(10, 2)); // 100
print(pow(2, -1)); // 0.5
print(pow(4, 0.5)); // 2.0Returns the logarithm of n to the given base (default: natural log).
Signature:
log(n: float, base?: float) -> floatParameters:
n- The numberbase- Optional: logarithm base (default: e)
Returns: float
Examples:
print(log(2.718)); // ≈ 1.0 (natural log)
print(log(100, 10)); // 2.0
print(log(8, 2)); // 3.0Returns e raised to the power of n (e^n).
Signature:
exp(n: float) -> floatParameters:
n- The exponent
Returns: float
Examples:
print(exp(0)); // 1.0
print(exp(1)); // 2.718...
print(exp(2)); // 7.389...Returns the sine of a number (in radians).
Signature:
sin(n: float) -> floatParameters:
n- Angle in radians
Returns: float
Examples:
print(sin(0)); // 0.0
// sin(pi/2) ≈ 1.0
// sin(pi) ≈ 0.0Returns the cosine of a number (in radians).
Signature:
cos(n: float) -> floatParameters:
n- Angle in radians
Returns: float
Examples:
print(cos(0)); // 1.0
// cos(pi/2) ≈ 0.0
// cos(pi) ≈ -1.0Returns the tangent of a number (in radians).
Signature:
tan(n: float) -> floatParameters:
n- Angle in radians
Returns: float
Examples:
print(tan(0)); // 0.0
// tan(pi/4) ≈ 1.0Returns the maximum value in a list.
Signature:
max(list: list<number>) -> numberParameters:
list- List of numbers
Returns: number - Largest value
Examples:
print(max([3, 7, 2, 9, 1])); // 9
print(max([3.5, 2.1, 8.9])); // 8.9
print(max([42])); // 42Returns the minimum value in a list.
Signature:
min(list: list<number>) -> numberParameters:
list- List of numbers
Returns: number - Smallest value
Examples:
print(min([3, 7, 2, 9, 1])); // 1
print(min([3.5, 2.1, 8.9])); // 2.1
print(min([42])); // 42Returns a random float between 0.0 (inclusive) and 1.0 (exclusive).
Signature:
random() -> floatParameters: None
Returns: float in range [0.0, 1.0)
Examples:
let r = random();
print(r); // e.g., 0.742891
let scaled = random() * 100;
print(to_int(scaled)); // Random int 0-99Returns a random integer in the range [min, max).
Signature:
randint(min: int, max: int) -> intParameters:
min- Minimum value (inclusive)max- Maximum value (exclusive)
Returns: int
Examples:
print(randint(1, 7)); // Random 1-6 (dice roll)
print(randint(1, 101)); // Random 1-100
print(randint(0, 2)); // 0 or 1 (coin flip)Returns the length of a string.
Signature:
len(s: string) -> intParameters:
s- A string
Returns: int - Number of characters
Examples:
print(len("Hello")); // 5
print(len("")); // 0
print(len("ProXPL")); // 6Returns the string in uppercase.
Signature:
upper(s: string) -> stringParameters:
s- A string
Returns: string - Uppercase version
Examples:
print(upper("hello")); // "HELLO"
print(upper("ProXPL")); // "PROXPL"
print(upper("123abc")); // "123ABC"Returns the string in lowercase.
Signature:
lower(s: string) -> stringParameters:
s- A string
Returns: string - Lowercase version
Examples:
print(lower("HELLO")); // "hello"
print(lower("ProXPL")); // "proxpl"
print(lower("ABC123")); // "abc123"Removes leading and trailing whitespace.
Signature:
trim(s: string) -> stringParameters:
s- A string
Returns: string - Trimmed string
Examples:
print(trim(" hello ")); // "hello"
print(trim("\t\nhello\n")); // "hello"
print(trim("world")); // "world"Splits a string into a list of substrings.
Signature:
split(s: string, sep: string) -> list<string>Parameters:
s- String to splitsep- Separator string
Returns: list
Examples:
let words = split("a,b,c", ",");
print(words); // ["a", "b", "c"]
let parts = split("one two three", " ");
print(parts); // ["one", "two", "three"]Joins list elements into a string with separator.
Signature:
join(sep: string, list: list) -> stringParameters:
sep- Separator stringlist- List to join
Returns: string
Examples:
let parts = ["one", "two", "three"];
print(join("-", parts)); // "one-two-three"
let nums = [1, 2, 3];
print(join(", ", nums)); // "1, 2, 3"Replaces all occurrences of old with new.
Signature:
replace(s: string, old: string, new: string) -> stringParameters:
s- Original stringold- Substring to findnew- Replacement string
Returns: string - Modified string
Examples:
print(replace("hello world", "world", "ProXPL"));
// "hello ProXPL"
print(replace("aaa", "a", "b"));
// "bbb"Checks if string starts with prefix.
Signature:
startswith(s: string, prefix: string) -> boolParameters:
s- String to checkprefix- Prefix to look for
Returns: bool
Examples:
print(startswith("hello", "he")); // true
print(startswith("hello", "world")); // false
print(startswith("", "")); // trueChecks if string ends with suffix.
Signature:
endswith(s: string, suffix: string) -> boolParameters:
s- String to checksuffix- Suffix to look for
Returns: bool
Examples:
print(endswith("hello", "lo")); // true
print(endswith("hello", "world")); // false
print(endswith("file.txt", ".txt")); // trueChecks if haystack contains needle substring.
Signature:
contains(haystack: string, needle: string) -> boolParameters:
haystack- String to search inneedle- Substring to find
Returns: bool
Examples:
print(contains("hello world", "world")); // true
print(contains("ProXPL", "XP")); // true
print(contains("abc", "xyz")); // falseReturns the index of the first occurrence of substring.
Signature:
index_of(s: string, sub: string) -> intParameters:
s- String to search insub- Substring to find
Returns: int - Index (0-based), or -1 if not found
Examples:
print(index_of("hello world", "world")); // 6
print(index_of("hello", "h")); // 0
print(index_of("hello", "x")); // -1Extracts a substring.
Signature:
substring(s: string, start: int, end?: int) -> stringParameters:
s- Original stringstart- Start index (inclusive)end- Optional: end index (exclusive, default: end of string)
Returns: string - Substring
Examples:
print(substring("hello", 0, 3)); // "hel"
print(substring("hello", 1)); // "ello"
print(substring("hello", 1, 4)); // "ell"Returns the character at the specified index.
Signature:
char_at(s: string, index: int) -> stringParameters:
s- Stringindex- Character index (0-based)
Returns: string - Single character
Examples:
print(char_at("hello", 0)); // "h"
print(char_at("hello", 4)); // "o"
print(char_at("hello", -1)); // Error (invalid index)Formats a string with printf-style placeholders.
Signature:
format(fmt: string, ...args) -> stringParameters:
fmt- Format string with %s, %d, %f, etc....args- Values to insert
Returns: string
Examples:
print(format("Hello, %s!", "World"));
// "Hello, World!"
print(format("Count: %d, Ratio: %.2f", 42, 3.14159));
// "Count: 42, Ratio: 3.14"Converts a string to bytes.
Signature:
to_bytes(s: string) -> bytesParameters:
s- String to convert
Returns: bytes
Examples:
let data = to_bytes("Hello");
print(data); // bytes objectReturns the number of elements in a collection.
Signature:
len(col: list|dict|string) -> intParameters:
col- A list, dict, or string
Returns: int
Examples:
print(len([1, 2, 3])); // 3
print(len({"a": 1, "b": 2})); // 2
print(len("hello")); // 5
print(len([])); // 0Appends an item to the end of a list.
Signature:
push(list: list, item: any) -> voidParameters:
list- List to modifyitem- Item to add
Returns: void
Examples:
let nums = [1, 2];
push(nums, 3);
print(nums); // [1, 2, 3]
let items = [];
push(items, "a");
push(items, "b");
print(items); // ["a", "b"]Removes and returns the last item from a list.
Signature:
pop(list: list) -> anyParameters:
list- List to modify
Returns: The removed item
Examples:
let nums = [1, 2, 3];
let last = pop(nums);
print(last); // 3
print(nums); // [1, 2]Inserts an item at a specific position.
Signature:
insert(list: list, index: int, item: any) -> voidParameters:
list- List to modifyindex- Position to insert atitem- Item to insert
Returns: void
Examples:
let nums = [1, 2, 3];
insert(nums, 1, 10);
print(nums); // [1, 10, 2, 3]Removes the first occurrence of an item.
Signature:
remove(list: list, item: any) -> voidParameters:
list- List to modifyitem- Item to remove
Returns: void
Examples:
let items = [1, 2, 3, 2];
remove(items, 2);
print(items); // [1, 3, 2]Sorts a list in ascending order.
Signature:
sort(list: list) -> voidParameters:
list- List to sort (modified in place)
Returns: void
Examples:
let nums = [3, 1, 4, 1, 5];
sort(nums);
print(nums); // [1, 1, 3, 4, 5]
let words = ["dog", "cat", "ant"];
sort(words);
print(words); // ["ant", "cat", "dog"]Reverses a list in place.
Signature:
reverse(list: list) -> voidParameters:
list- List to reverse
Returns: void
Examples:
let nums = [1, 2, 3];
reverse(nums);
print(nums); // [3, 2, 1]Creates a list of numbers from start to end.
Signature:
range(start: int, end: int, step?: int) -> list<int>Parameters:
start- Start value (inclusive)end- End value (exclusive)step- Optional: increment (default: 1)
Returns: list
Examples:
print(range(0, 5)); // [0, 1, 2, 3, 4]
print(range(1, 6)); // [1, 2, 3, 4, 5]
print(range(0, 10, 2)); // [0, 2, 4, 6, 8]
print(range(5, 0, -1)); // [5, 4, 3, 2, 1]Returns all keys of a dictionary as a list.
Signature:
keys(dict: dict) -> list<string>Parameters:
dict- Dictionary
Returns: list
Examples:
let person = {"name": "Alice", "age": 30};
print(keys(person)); // ["name", "age"]Returns all values of a dictionary as a list.
Signature:
values(dict: dict) -> list<any>Parameters:
dict- Dictionary
Returns: list
Examples:
let person = {"name": "Alice", "age": 30};
print(values(person)); // ["Alice", 30]Returns all key-value pairs as a list of lists.
Signature:
entries(dict: dict) -> list<list>Parameters:
dict- Dictionary
Returns: list of [key, value] pairs
Examples:
let person = {"name": "Alice", "age": 30};
let pairs = entries(person);
// [["name", "Alice"], ["age", 30]]Checks if a dictionary has a key.
Signature:
contains_key(dict: dict, key: string) -> boolParameters:
dict- Dictionarykey- Key to check
Returns: bool
Examples:
let person = {"name": "Alice", "age": 30};
print(contains_key(person, "name")); // true
print(contains_key(person, "city")); // falseMerges two dictionaries.
Signature:
merge(dict1: dict, dict2: dict) -> dictParameters:
dict1- First dictionarydict2- Second dictionary
Returns: dict - New merged dictionary
Examples:
let d1 = {"a": 1, "b": 2};
let d2 = {"b": 3, "c": 4};
let merged = merge(d1, d2);
// {"a": 1, "b": 3, "c": 4}Creates a shallow copy of a collection.
Signature:
clone(col: list|dict) -> list|dictParameters:
col- Collection to copy
Returns: Shallow copy
Examples:
let original = [1, 2, [3, 4]];
let copy = clone(original);
// Modifying top level doesn't affect original
copy[0] = 99; // original[0] still 1
// But nested lists are shared
copy[2][0] = 99; // original[2][0] is now 99Creates a deep copy of a collection (recursive).
Signature:
deep_clone(col: list|dict) -> list|dictParameters:
col- Collection to copy
Returns: Deep copy
Examples:
let original = [1, 2, [3, 4]];
let copy = deep_clone(original);
copy[2][0] = 99; // original[2][0] still 3Removes all elements from a collection.
Signature:
clear(col: list|dict) -> voidParameters:
col- Collection to clear
Returns: void
Examples:
let nums = [1, 2, 3];
clear(nums);
print(nums); // []
let person = {"name": "Alice"};
clear(person);
print(person); // {}Converts a value to an integer.
Signature:
to_int(value: any) -> intParameters:
value- Value to convert
Returns: int
Examples:
print(to_int(3.7)); // 3 (truncated)
print(to_int("42")); // 42
print(to_int(true)); // 1
print(to_int(false)); // 0Converts a value to a float.
Signature:
to_float(value: any) -> floatParameters:
value- Value to convert
Returns: float
Examples:
print(to_float(3)); // 3.0
print(to_float("3.14")); // 3.14
print(to_float(true)); // 1.0Converts a value to a string.
Signature:
to_string(value: any) -> stringParameters:
value- Value to convert
Returns: string
Examples:
print(to_string(42)); // "42"
print(to_string(3.14)); // "3.14"
print(to_string(true)); // "true"
print(to_string([1, 2, 3])); // "[1, 2, 3]"Converts a value to a boolean.
Signature:
to_bool(value: any) -> boolParameters:
value- Value to convert
Returns: bool
Examples:
print(to_bool(1)); // true
print(to_bool(0)); // false
print(to_bool("")); // false
print(to_bool("text")); // true
print(to_bool(null)); // falseConverts a value to a list.
Signature:
to_list(value: any) -> listParameters:
value- Value to convert
Returns: list
Examples:
print(to_list("abc")); // ["a", "b", "c"]
print(to_list(range(1, 4))); // [1, 2, 3]Converts a value to a dictionary.
Signature:
to_dict(value: any) -> dictParameters:
value- Value to convert (typically list of pairs)
Returns: dict
Examples:
let pairs = [["a", 1], ["b", 2]];
let dict = to_dict(pairs);
// {"a": 1, "b": 2}Converts an integer to hexadecimal string.
Signature:
to_hex(value: int) -> stringParameters:
value- Integer to convert
Returns: string
Examples:
print(to_hex(255)); // "ff"
print(to_hex(256)); // "100"
print(to_hex(4095)); // "fff"Converts an integer to binary string.
Signature:
to_bin(value: int) -> stringParameters:
value- Integer to convert
Returns: string
Examples:
print(to_bin(5)); // "101"
print(to_bin(255)); // "11111111"Parses a JSON string into a value.
Signature:
parse_json(str: string) -> anyParameters:
str- JSON string
Returns: Parsed value
Examples:
let data = parse_json('{"name": "Alice", "age": 30}');
print(data["name"]); // "Alice"Converts a value to JSON string.
Signature:
stringify_json(value: any) -> stringParameters:
value- Value to convert
Returns: string
Examples:
let obj = {"name": "Alice", "age": 30};
let json = stringify_json(obj);
// '{"name":"Alice","age":30}'Returns the current time in seconds since epoch.
Signature:
clock() -> floatParameters: None
Returns: float
Examples:
let start = clock();
// ... do work ...
let elapsed = clock() - start;
print("Elapsed: " + to_string(elapsed) + " seconds");Pauses execution for the specified milliseconds.
Signature:
sleep(ms: int) -> voidParameters:
ms- Milliseconds to sleep
Returns: void
Examples:
print("Starting");
sleep(1000); // Wait 1 second
print("Done");Exits the program with a status code.
Signature:
exit(code: int) -> voidParameters:
code- Exit code (0 = success)
Returns: void (doesn't return)
Examples:
if (error) {
print("Error occurred");
exit(1);
}
exit(0); // SuccessReturns information about the platform.
Signature:
platform() -> stringParameters: None
Returns: string - "Linux", "Windows", "Darwin", etc.
Examples:
let os = platform();
if (os == "Windows") {
print("Running on Windows");
}Executes a system command and returns output.
Signature:
exec(command: string) -> stringParameters:
command- Command to execute
Returns: string - Command output
Examples:
let output = exec("ls -la");
print(output);Returns the current timestamp (seconds since epoch).
Signature:
now() -> floatParameters: None
Returns: float
Examples:
let current = now();
print(to_string(current));Converts a date string to timestamp.
Signature:
timestamp(date_string: string) -> floatParameters:
date_string- Date in format "YYYY-MM-DD HH:MM:SS"
Returns: float
Examples:
let ts = timestamp("2024-12-11 12:00:00");
print(to_string(ts));Formats a timestamp as a string.
Signature:
format_date(timestamp: float, format: string) -> stringParameters:
timestamp- Time valueformat- Format string ("%Y-%m-%d", etc.)
Returns: string
Examples:
let ts = now();
print(format_date(ts, "%Y-%m-%d %H:%M:%S"));
// "2024-12-11 15:30:42"Parses a date string into timestamp.
Signature:
parse_date(date_string: string) -> floatParameters:
date_string- Date string
Returns: float
Examples:
let ts = parse_date("2024-12-11");
print(to_string(ts));Returns the type name of a value.
Signature:
typeof(value: any) -> stringParameters:
value- Any value
Returns: string - Type name
Examples:
print(typeof(42)); // "int"
print(typeof(3.14)); // "float"
print(typeof("hello")); // "string"
print(typeof([1, 2])); // "list"
print(typeof(true)); // "bool"
print(typeof(null)); // "null"
print(typeof(print)); // "function"Asserts a condition is true, throws error if false.
Signature:
assert(condition: bool, message?: string) -> voidParameters:
condition- Condition to checkmessage- Optional: error message
Returns: void
Examples:
assert(5 > 3);
assert(len(list) > 0, "List must not be empty");Returns the identity (memory address) of an object.
Signature:
id(value: any) -> intParameters:
value- Any value
Returns: int
Examples:
let obj = {"a": 1};
print(to_string(id(obj))); // Some large numberReturns the hash value of an object.
Signature:
hash(value: any) -> intParameters:
value- Value to hash
Returns: int
Examples:
let h1 = hash("hello");
let h2 = hash("hello");
// h1 == h2 (same string has same hash)Checks if a value is an instance of a type.
Signature:
is_instance(value: any, type: string) -> boolParameters:
value- Value to checktype- Type name as string
Returns: bool
Examples:
print(is_instance(42, "int")); // true
print(is_instance("hello", "int")); // false
print(is_instance([1, 2], "list")); // trueI/O (5): print, input, read_file, write_file, append_file Math (15): abs, ceil, floor, round, sqrt, pow, log, exp, sin, cos, tan, max, min, random, randint String (15): len, upper, lower, trim, split, join, replace, startswith, endswith, contains, index_of, substring, char_at, format, to_bytes Collections (15): len, push, pop, insert, remove, sort, reverse, range, keys, values, entries, contains_key, merge, clone, deep_clone, clear Type Conversion (10): to_int, to_float, to_string, to_bool, to_list, to_dict, to_hex, to_bin, parse_json, stringify_json System (5): clock, sleep, exit, platform, exec DateTime (5): now, timestamp, format_date, parse_date Runtime (5): typeof, assert, id, hash, is_instance
Total: 75+ functions
See the specific sections above for detailed documentation and examples.