zedocs
GitHub ↗
Language

Built-in functions

Reference for Ze core functions, type conversions, math, and string utilities.

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

FunctionSignatureDescription
typetype(x)Returns the type of x as a string: "number", "word", "truth", "list", or "null"
numnum(x)Convert x to a number (parses strings, coerces booleans)
word / strword(x)Convert x to its string representation
lenlen(x)Length of a list or string (character count)
rangerange(n)Returns [0, 1, ..., n-1]
rangerange(start, end)Returns [start, start+1, ..., end-1]
rangerange(start, end, step)Returns every step-th value from start up to (not including) end
inputinput(prompt?)Print optional prompt, then read a line from stdin
intint(x)Truncate a number to its integer part
boolbool(x)Convert to boolean (0, "", nothing, false -> false; everything else -> true)
listlist(x)Wrap a single value in a list
parse_numparse_num(s)Parse a string as a number; returns nothing if it cannot be parsed
randomrandom()Random float in [0, 1)
randintrandint(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

FunctionDescription
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 / PIpi ~= 3.14159265358979
e / EEuler’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

FunctionSignatureDescription
upperupper(s)Convert to uppercase
lowerlower(s)Convert to lowercase
trimtrim(s)Remove leading and trailing whitespace
reversereverse(s)Reverse the string
splitsplit(s, sep?)Split into a list; default separator is a single space
joinjoin(list, sep?)Join a list of values into a string; default separator is ""
containscontains(s, sub)true if sub appears inside s
starts_withstarts_with(s, prefix)true if s starts with prefix
ends_withends_with(s, suffix)true if s ends with suffix
replacereplace(s, old, new)Replace the first occurrence of old with new
index_ofindex_of(s, sub)Index of first occurrence of sub; -1 if not found
substrsubstr(s, start, end)Substring from index start (inclusive) to end (exclusive)
repeat_strrepeat_str(s, n)Repeat string s exactly n times
is_alphais_alpha(s)true if every character is a letter
is_digitis_digit(s)true if every character is a digit
char_codechar_code(s)Unicode code point of the first character of s
from_char_codefrom_char_code(n)Character with Unicode code point n
formatformat(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.

FunctionDescription
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
Help make these docs better.Edit this page on GitHub ↗

Find a guide or search the language reference.