Repository navigation
Standard Library
torvik-lang edited this page Jul 7, 2026
·
8 revisions
Important
[07/26] The Torvik Wiki is currently in the process of being updated to reflect the latest changes that came with v1.1.0 of Torvik. As we're working to get it updated, please feel free to check out the docs or the readme, which are both always up to date in the meantime. If you don't see this notice on a wiki page, then it means it has been updated and is current. Thank you for you patience.
Torvik provides two layers of built-in functionality:
-
Core Builtins — Always available, no
applyneeded. -
Standard Library (
std) — Opt-in withapply std;
-
len(s)— length of string (or list) -
str_concat(a, b)— concatenate two strings -
substr(s, start, end)— substring -
char_at(s, i)/byte_at(s, i)— access characters/bytes -
trim(s),triml(s),trimr(s) replace(s, old, new)-
contains(s, sub),starts(s, prefix),ends(s, suffix) -
split(s, sep)— returnslist<str> -
fmt(...)— string formatting (named or positional)
-
toint(s),tofloat(s) -
tostr(x),int_to_str(n),float_to_str(f)
-
abs(n),min(a, b),max(a, b) -
randint(lo, hi),rand()
Lists (list<T>):
list_new()push(xs, x)-
list_insert(xs, i, x),list_remove(xs, i) -
len(xs),xs[i]
Tables (table<K, V>):
table_new()-
table_set(t, k, v),table_get(t, k) -
table_has(t, k),table_del(t, k)
Bags (bag<T>):
-
bag_new(),bag_add(b, x),bag_has(b, x), etc.
-
readln(),readint(),readfloat(),readbool() readenv(name)
-
readfile(path),writefile(path, content) -
fs_exists(path),fs_mkdir(path),fs_remove(path) -
exit(code),sys_run(cmd) -
args(),args_get(i) -
sleep(ms),clear_screen()
-
time_ms(),datetime_str(), etc.
Bring in additional helpers with:
apply std; // everything
// or
apply std::math;
apply std::strings;
apply std::list;
-
std::math:pow,gcd,lcm,clamp,factorial, etc. -
std::strings:join,repeat_str,pad_left,pad_right -
std::list:range(start, stop),sum(xs),list_max,list_min
- See what's on the Roadmap for Torvik.
- Find out how to Contribute to Torvik.
- Have any questions? See our FAQ's.
- See the full detailed reference in the repo: docs/STDLIB.md