Skip to content

Torvik v1.4.0 — Optional & variadic parameters, and networking

Choose a tag to compare

@torvik-lang torvik-lang released this 22 Jul 19:32
· 71 commits to main since this release
Immutable release. Only release title and notes can be modified.
e5550e5

Torvik v1.4.0 makes function calls more flexible and safer, closes the last of the
expression-chaining rough edges, and adds a small, opt-in HTTP layer so Torvik programs
can serve files and answer requests. The compiler remains fully self-hosting — it builds
itself byte-identically on Linux and Windows.

Highlights

Optional (^) and variadic (*) parameters.
Mark a trailing parameter ^ and callers may omit it (it takes a type-appropriate zero),
or * to gather the remaining arguments into a list<T>. They combine in the order
required → optional → variadic, and wrong argument counts are clean, located range errors.

df greet(name: str, ^count: i64) -> void {
    echo!("hi {name} x{count}");
}
greet("a");        // hi a x0
greet("b", 3);     // hi b x3

df join_words(sep: str, *words: str) -> str { /* ... */ }
join_words(", ", "a", "b", "c");   // a, b, c

Arguments are type-checked at the call site.
Passing an argument whose type can't match the parameter — a number where a string is
expected, a decimal where an integer is expected, a list where a scalar is expected — is
now a clean error instead of silent garbage or a crash at run time. Ambiguous cases are
left alone, so correct programs are never rejected.

Boolean chaining is limit-free.
&& and || now work as values bound to a variable (fixed ok: bool = a && b;,
including three-way), not just inside conditions, and a boolean-returning builtin or user
function can be compared to a literal:

fixed ready: bool = a && b;
check contains(line, "error") == false { ... }

std::net — a minimal HTTP layer.
apply std::net; brings in request parsing, MIME types, path_is_safe, and response
builders over transport primitives — net_listen, net_accept, net_recv, net_send,
net_send_file, net_close — that dead-strip out of programs that never call them, so
you pay nothing unless you use them. net_send_file streams bytes verbatim, so binary
assets serve intact. It's enough to serve a static site or a small localhost API (and it
powers Vefna's new vefna serve).

Also: chr(code) and fs_size(path) builtins; standard library v1.3.0.

rune has moved

As of this release, rune lives in its own repository —
https://github.com/torvik-lang/rune — and versions independently. It still installs
alongside torvc and manages Torvik exactly as before; rune update moves you to the
latest of both.

Fixes

  • Exhaustive when no longer trips a flow-checker false positive.
  • A boolean literal passed as an argument no longer produces malformed IR.
  • A bool (or narrow-int) value returned from a user function is now stored correctly.
  • Single-character function names (a, g, p, …) resolve everywhere — previously they
    could be wrongly reported "undefined" when apply std; was present.

Install / upgrade

Already on Torvik? Just run rune update.

New install (needs clang on your PATH):

# Linux
curl -fsSL https://raw.githubusercontent.com/torvik-lang/torvik/main/linux/install.sh | sh
# Windows (PowerShell)
iwr -useb https://raw.githubusercontent.com/torvik-lang/torvik/main/windows/install.ps1 | iex

Linux and Windows (x86-64); macOS is planned once real Apple hardware is available for
testing.

Links