Scoria Language
Scoria is a compiled, memory-safe systems programming language (.sco) that compiles via C to standalone native binaries without garbage collection. Mutation is explicit at both function parameters and call sites, and errors are ordinary values.
Language Tour
Four programs demonstrating tagged enums, explicit call-site mutation, error values, and structural interfaces.
Tagged enums with attached methods, exhaustive pattern matching, and formatted string interpolation.
use std.math
enum shape {
circle(float r)
rect(float w, float h)
float area() {
switch ~ {
circle(r): return math.pi * r * r
rect(w, h): return w * h
}
}
}
main() {
shape[] shapes = [circle(1.0), rect(2.0, 3.0)]
for s in shapes {
print("{s} has area {s.area():.2}")
}
}
circle(r: 1.0) has area 3.14
rect(w: 2.0, h: 3.0) has area 6.00
Functions that mutate an argument require & on both the parameter declaration and the call site.
grow(&int[] xs, int n) {
xs.push(n)
}
main() {
int[] xs = [1, 2]
grow(xs, 3)
}
grow.sco:7:10: error: grow changes this argument, so mark it: &xs (the & shows the change at the call)
grow(xs, 3)
^
1 error
Errors are values: a function that can fail declares its error type after |, with ?, ??, and else e { }.
int parse_age(str s) | error {
int n = int(s)?
if n < 0 {
return error("{n} is below zero")
}
return n
}
main() {
print(parse_age("31") ?? 0)
print(parse_age("abc") ?? 0)
int age = parse_age("-4") else e {
print("bad age: {e.message}")
return
}
print(age)
}
31
0
bad age: -4 is below zero
Interfaces list methods structurally. Any type with those methods fits without inheritance hierarchies.
interface shape {
float area()
}
struct square {
float side
float area() { return ~side * ~side }
}
struct circle {
float r
float area() { return 3.14 * ~r * ~r }
}
main() {
shape[] all = [square(1), circle(2)]
for s in all {
print(s.area())
}
}
1.0
12.56
The Scoria Book
Twenty-three chapters and six appendices covering the language from installation and value semantics to raw C interop and the compiler internals.
Warming Up
Installation, the scoria command, variables, control flow, text, lists, maps, and a complete first project.
The Scoria Way
Copy-on-write value semantics, explicit & call-site mutation, maybe-values with none narrowing, and errors as values.
Building Real Things
Structs and ~ methods, tagged enums with switch, structural interfaces, generics, lambdas, modules, and testing.
The Deep End & Reference
Shared and weak references, defer resources, trust raw pointers and C FFI, compiler internals, and cheat sheets.
Toolchain
The scoria executable packages compilation, incremental split-TU caching, -g debug builds, testing, formatting, trust auditing, and an LSP server in one self-hosted binary, with native support in Basalt IDE and 27 standard modules.
scoria run [-g] <file.sco>
Compile via C and execute a Scoria program immediately.
scoria build [-g] <file.sco>
Emit a standalone native binary with incremental .scoria-cache/ builds and #line debug info under -g.
scoria check <file.sco>
Type-check and validate mutation and error contracts without linking.
scoria test [-g] [file.sco]
Discover and execute isolated project test suites.
scoria fmt [--check] <files...>
Format Scoria source files to canonical style.
scoria audit <file.sco> [--std]
Report all trust blocks, raw pointers, and extern C functions.
scoria init / deps / new
Initialize projects and inspect scoria.toml dependencies and C [build] flags.
scoria lsp
Start the Language Server Protocol daemon for Basalt IDE and compatible editors.
scoria emit-c [-g] <file.sco>
Inspect the generated C source output directly.
scoria version
Print the installed compiler and toolchain version.