Skip to content

Standard Library

torvik-lang edited this page Jul 7, 2026 · 8 revisions

Standard Library Reference (v1.0)

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:

  1. Core Builtins — Always available, no apply needed.
  2. Standard Library (std) — Opt-in with apply std;

Core Builtins

Strings

  • 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) — returns list<str>
  • fmt(...) — string formatting (named or positional)

Conversions

  • toint(s), tofloat(s)
  • tostr(x), int_to_str(n), float_to_str(f)

Math

  • abs(n), min(a, b), max(a, b)
  • randint(lo, hi), rand()

Collections

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.

Console Input

  • readln(), readint(), readfloat(), readbool()
  • readenv(name)

Files & System

  • 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

  • time_ms(), datetime_str(), etc.

Standard Library (apply std;)

Bring in additional helpers with:

apply std;                    // everything
// or
apply std::math;
apply std::strings;
apply std::list;

Key Modules

  • 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

Next Steps

Clone this wiki locally