Builtins
generated from midad spec --json at build time; not edited by hand
72 builtins, each with every parameter set it accepts and the type it returns. A | separates the types one argument may take.
core
len(list|string|map) -> numberThe number of elements, characters or keys.
read_file(string) -> optionReads a file as text; None when it cannot be read. Needs fs_read.
write_file(string, string) -> booleanWrites text to a file and answers whether it worked. Needs fs_write.
write_file(string) -> booleanwrite_file(string) -> boolean
http_get(string) -> optionFetches a URL and answers the body as text, or None. Needs net.
json_get(string, string) -> optionReads one key out of JSON text; None when the text or the key is missing.
json_get(string) -> optionjson_get(string) -> option
html(string) -> stringRenders an html:NAME template, optionally binding its holes from a map.
str(number|float|string|boolean|list|map|option|result|any) -> stringAny value as a string; lists and maps come out as compact JSON.
int(number|float|string) -> numberA number from a number, a float or a whole-number string. A bad string is a runtime error.
int_or(string, number) -> numberA number from a string, or the fallback when it cannot be parsed.
int_or(string) -> numberint_or(number) -> number
float_or(string, float|number) -> floatA float from a string, or the fallback.
float_or(string) -> floatfloat_or(float, number) -> float
float(number|float|string) -> floatA float from a number, a float or a numeric string.
print(number|float|string|boolean|list|map|option|result|any) -> voidWrites a value and a newline to standard output.
push(list, number|float|string|boolean|list|map|option|result|any) -> voidChanges its first argument in place and answers nothing, so the call is a statement on its own; using its result is E0260.
Adds one element to the end of the list, in place; the call answers nothing.
push(list) -> voidpush(number, float, string, boolean, list, map, option, result, any) -> void
at(list, number) -> anyThe element at an index, as any. A bad index is a runtime error.
at(list) -> anyat(number) -> any
idiv(number, number) -> numberInteger division, floored: idiv(-7, 2) is -4. A zero denominator is a runtime error.
idiv(number) -> numberidiv(number) -> number
set_at(list, number, number|float|string|boolean|list|map|option|result|any) -> voidChanges its first argument in place and answers nothing, so the call is a statement on its own; using its result is E0260.
Replaces the element at an index, in place; the call answers nothing.
set_at(list) -> voidset_at(number) -> voidset_at(number, float, string, boolean, list, map, option, result, any) -> void
remove_at(list, number) -> anyChanges its first argument in place, and answers the element it removed.
Removes the element at an index, in place, and answers the element it removed.
remove_at(list) -> anyremove_at(number) -> any
get(map, string) -> anyThe value for a key, as any; None when the key is absent.
get(map) -> anyget(string) -> any
has(map, string) -> booleanWhether a map has a key.
has(map) -> booleanhas(string) -> boolean
put(map, string, number|float|string|boolean|list|map|option|result|any) -> mapChanges its first argument in place, and answers the element it removed.
A new map with a key set to a value.
put(map) -> mapput(string) -> mapput(number, float, string, boolean, list, map, option, result, any) -> map
del(map, string) -> mapChanges its first argument in place, and answers the element it removed.
A new map without a key.
del(map) -> mapdel(string) -> map
keys(map) -> listThe keys of a map, in byte order.
Some(number|float|string|boolean|list|map|option|result|any) -> optionWraps a value in a non-empty option.
Ok(number|float|string|boolean|list|map|option|result|any) -> resultWraps a value in a successful result.
Err(number|float|string|boolean|list|map|option|result|any) -> resultWraps a reason in a failed result.
is_some(option) -> booleanWhether an option holds a value.
is_none(option) -> booleanWhether an option is empty.
unwrap_or(option|result, number|float|string|boolean|list|map|option|result|any) -> anyThe value inside an option or result, or the fallback.
unwrap_or(option, result) -> anyunwrap_or(number, float, string, boolean, list, map, option, result, any) -> any
is_ok(result) -> booleanWhether a result is Ok.
is_err(result) -> booleanWhether a result is Err.
respond(number, number|float|string|boolean|list|map|option|result|any, number|float|string|boolean|list|map|option|result|any) -> mapA response for a route: status 100 to 599, a body, and optionally headers.
respond(number) -> maprespond(number, float, string, boolean, list, map, option, result, any) -> maprespond(number, float, string, boolean, list, map, option, result, any) -> map
respond_html(number, string) -> mapA response whose body is sent as HTML.
respond_html(number) -> maprespond_html(string) -> map
eval_source(string) -> mapRuns a string as a program and answers a map with its output. Needs eval.
split(string, string) -> listSplits a string on a non-empty separator.
split(string) -> listsplit(string) -> list
trim(string) -> stringThe string without leading and trailing whitespace.
contains(string|list, number|float|string|boolean|list|map|option|result|any) -> booleanWhether a string contains a substring, or a list an element.
contains(string, list) -> booleancontains(number, float, string, boolean, list, map, option, result, any) -> boolean
is_null(number|float|string|boolean|list|map|option|result|any) -> booleanWhether a value is null: a SQL NULL from db.query, a JSON null, or the null literal. Not true of None.
type_of(number|float|string|boolean|list|map|option|result|any) -> stringThe runtime kind: int, float, string, bool, list, map, option, result, null.
chars(string) -> listA list of one-character strings.
join(list, string) -> stringJoins a list of strings with a separator.
join(list) -> stringjoin(string) -> string
upper(string) -> stringThe string in upper case. A native C build refuses it.
lower(string) -> stringThe string in lower case. A native C build refuses it.
replace(string, string, string) -> stringEvery occurrence of a substring replaced with another.
replace(string) -> stringreplace(string) -> stringreplace(string) -> string
substr(string, number, number) -> stringA slice: start index and length.
substr(string) -> stringsubstr(number) -> stringsubstr(number) -> string
sort(list) -> voidChanges its first argument in place and answers nothing, so the call is a statement on its own; using its result is E0260.
Sorts the list in place; the call answers nothing.
starts_with(string, string) -> booleanWhether a string starts with a prefix.
starts_with(string) -> booleanstarts_with(string) -> boolean
int builtins
int.parse(string) -> optionA number as an option: None for anything that is not a whole number.
float builtins
float.parse(string) -> optionA float as an option: None for anything that is not a number.
json builtins
json.parse(string) -> anyParses JSON text into a value; None when the text is not JSON.
json.at(number|float|string|boolean|list|map|option|result|any, string) -> anyReads one key out of a parsed JSON value.
json.at(number, float, string, boolean, list, map, option, result, any) -> anyjson.at(string) -> any
json.stringify(number|float|string|boolean|list|map|option|result|any) -> stringA value as JSON text.
time builtins
time.now() -> numberThe current time in milliseconds since the epoch.
time.iso(number) -> stringAn ISO-8601 timestamp with milliseconds, in UTC.
time.date(number) -> stringThe date part, YYYY-MM-DD.
time.parse(string) -> optionA timestamp string as an option of milliseconds.
time.add_days(number, number) -> numberA time in milliseconds moved by a number of days.
time.add_days(number) -> numbertime.add_days(number) -> number
fs builtins
fs.read(string) -> stringReads a file as text and fails with a runtime error when it cannot. Needs fs_read.
fs.write(string, string) -> booleanWrites text to a file. Needs fs_write.
fs.write(string) -> booleanfs.write(string) -> boolean
env builtins
env.get(string) -> stringAn environment variable as a string. Needs env.
crypto builtins
crypto.sha256(string) -> stringThe SHA-256 of a string, as hex.
crypto.hmac_sha256(string, string) -> stringThe HMAC-SHA256 of a message under a key, as hex.
crypto.hmac_sha256(string) -> stringcrypto.hmac_sha256(string) -> string
crypto.pbkdf2_sha256(string, string, number, number) -> stringPBKDF2-HMAC-SHA256 from a password, a salt, an iteration count and a key length.
crypto.pbkdf2_sha256(string) -> stringcrypto.pbkdf2_sha256(string) -> stringcrypto.pbkdf2_sha256(number) -> stringcrypto.pbkdf2_sha256(number) -> string
hex builtins
hex.encode(string) -> stringThe bytes of a string as hex.
hex.decode(string) -> optionHex as a string, or None when it is not valid hex.
random builtins
random.hex(number) -> stringRandom bytes as hex: the argument is how many bytes.
db builtins
db.open(string) -> numberOpens a SQLite database and answers a connection. Needs db.
db.close(number) -> anyCloses a connection.
db.query(number, string, list) -> listRuns a query with bound parameters and answers a list of row maps, at most 10,000.
db.query(number) -> listdb.query(string) -> listdb.query(list) -> list
db.exec(number, string, list) -> numberRuns a statement with bound parameters and answers the affected row count.
db.exec(number) -> numberdb.exec(string) -> numberdb.exec(list) -> number
db.begin(number) -> anyOpens a transaction on a connection.
db.commit(number) -> anyCommits the open transaction.
db.rollback(number) -> anyRolls the open transaction back.