All built-in functions are available in every Ze program without any imports.
SQLite functions (db_open, db_query, db_exec, db_close) and their Bisaya equivalents are documented in database.md.
Core
| Function | Signature | Description |
|---|
type | type(x) | Returns the type of x as a string: "number", "word", "truth", "list", or "null" |
num | num(x) | Convert x to a number (parses strings, coerces booleans) |
word / str | word(x) | Convert x to its string representation |
len | len(x) | Length of a list or string (character count) |
range | range(n) | Returns [0, 1, ..., n-1] |
range | range(start, end) | Returns [start, start+1, ..., end-1] |
range | range(start, end, step) | Returns every step-th value from start up to (not including) end |
input | input(prompt?) | Print optional prompt, then read a line from stdin |
int | int(x) | Truncate a number to its integer part |
bool | bool(x) | Convert to boolean (0, "", nothing, false -> false; everything else -> true) |
list | list(x) | Wrap a single value in a list |
parse_num | parse_num(s) | Parse a string as a number; returns nothing if it cannot be parsed |
random | random() | Random float in [0, 1) |
randint | randint(a, b) | Random integer in the closed range [a, b] |
show type(42) # number
show type("hello") # word
show type(true) # truth
show type([1,2,3]) # list
show type(nothing) # null
show num("3.14") # 3.14
show word(100) # "100"
show len("hello") # 5
show len([1, 2, 3]) # 3
for i in range(3):
show i # 0, 1, 2
show int(3.9) # 3
show bool(0) # false
show bool("hi") # true
show parse_num("abc") # nothing
show randint(1, 6) # random 1-6
Math
| Function | Description |
|---|
sqrt(x) | Square root of x |
abs(x) | Absolute value |
ceil(x) | Smallest integer >= x |
floor(x) | Largest integer <= x |
round(x) | Round to nearest integer (half-away-from-zero) |
pow(base, exp) | base raised to the power exp |
log(x) | Natural logarithm (base e) |
log10(x) | Base-10 logarithm |
log2(x) | Base-2 logarithm |
exp(x) | e raised to x |
sin(x) | Sine (radians) |
cos(x) | Cosine (radians) |
tan(x) | Tangent (radians) |
asin(x) | Inverse sine |
acos(x) | Inverse cosine |
atan(x) | Inverse tangent |
atan2(y, x) | Two-argument arctangent |
hypot(a, b) | sqrt(a^2 + b^2) |
min(a, b, ...) | Minimum of all arguments |
max(a, b, ...) | Maximum of all arguments |
sum(list) | Sum of all numbers in a list |
pi / PI | pi ~= 3.14159265358979 |
e / E | Euler’s number ~= 2.71828182845905 |
show sqrt(16) # 4
show abs(-7) # 7
show ceil(3.2) # 4
show floor(3.9) # 3
show round(3.5) # 4
show pow(2, 10) # 1024
show log(e) # 1
show min(3, 1, 4, 1, 5) # 1
show max(3, 1, 4, 1, 5) # 5
show sum([1, 2, 3, 4, 5]) # 15
show pi # 3.141592653589793
Strings
| Function | Signature | Description |
|---|
upper | upper(s) | Convert to uppercase |
lower | lower(s) | Convert to lowercase |
trim | trim(s) | Remove leading and trailing whitespace |
reverse | reverse(s) | Reverse the string |
split | split(s, sep?) | Split into a list; default separator is a single space |
join | join(list, sep?) | Join a list of values into a string; default separator is "" |
contains | contains(s, sub) | true if sub appears inside s |
starts_with | starts_with(s, prefix) | true if s starts with prefix |
ends_with | ends_with(s, suffix) | true if s ends with suffix |
replace | replace(s, old, new) | Replace the first occurrence of old with new |
index_of | index_of(s, sub) | Index of first occurrence of sub; -1 if not found |
substr | substr(s, start, end) | Substring from index start (inclusive) to end (exclusive) |
repeat_str | repeat_str(s, n) | Repeat string s exactly n times |
is_alpha | is_alpha(s) | true if every character is a letter |
is_digit | is_digit(s) | true if every character is a digit |
char_code | char_code(s) | Unicode code point of the first character of s |
from_char_code | from_char_code(n) | Character with Unicode code point n |
format | format(template, ...) | Printf-style string formatting |
show upper("hello") # HELLO
show lower("WORLD") # world
show trim(" hi ") # "hi"
show reverse("Ze") # "atiles"
set words = split("a b c")
show words # [a, b, c]
show join(words, "-") # a-b-c
show contains("hello", "ell") # true
show starts_with("Ze", "sal") # true
show ends_with("Ze", "ita") # true
show replace("hello", "l", "r") # herlo
show index_of("Ze", "a") # 1
show substr("Ze", 0, 3) # sal
show repeat_str("ab", 3) # ababab
show is_alpha("hello") # true
show is_digit("123") # true
show char_code("A") # 65
show from_char_code(65) # A
show format("Hello, %s! You are %d years old.", "Zyron", 25)
# Hello, Zyron! You are 25 years old.
Web Built-ins
These functions are only available inside files running in web mode (Ze -web). See web.md for details.
| Function | Description |
|---|
respond(text) | Send a plain-text HTTP response |
respond_html(html) | Send an HTML response |
respond_json(value) | Serialize value as JSON and send it |
set_status(code) | Set the HTTP response status code |
set_header(name, value) | Set a response header |
get_param(name) | Get a URL query parameter value |
get_method() | Get the request HTTP method string ("GET", "POST", etc.) |
get_path() | Get the request URL path |
redirect(url) | Send an HTTP redirect |