Skip to main content

🦭 Walrus Programming Language

Welcome to Walrus

Walrus is a dynamically-typed, interpreted programming language that combines simplicity with power. It features both a tree-walking interpreter and a bytecode virtual machine for efficient execution, along with a mark-and-sweep garbage collector and comprehensive support for modern programming paradigms.

Key features

Bytecode VM

High-performance stack-based virtual machine with 80+ opcodes, call frames, and tail call optimization

JIT compilation

Optional Cranelift-powered JIT compiler for hot loops with up to 68x speedup on intensive computations

First-class functions

Functions as values with nested function support, closures, and higher-order functions

Automatic memory management

Mark-and-sweep garbage collector with configurable thresholds and arena-based heap allocation

Rich data types

Integers, floats, strings, booleans, lists, tuples, dictionaries, and ranges with comprehensive operations

Standard library

File I/O, system operations, and comprehensive math utilities with import system

Language highlights

Clean, expressive syntax

fn factorial : n {
    if n <= 1 {
        return 1;
    }
    return n * factorial(n - 1);
}

let result = factorial(5);  // 120
println(f"5! = {result}");

Structs and methods

struct Point {
    fn new : x, y {
        return {"x": x, "y": y};
    }

    fn distance : p1, p2 {
        let dx = p1["x"] - p2["x"];
        let dy = p1["y"] - p2["y"];
        return (dx * dx + dy * dy) ** 0.5;
    }
}

let p1 = Point.new(3, 4);
let p2 = Point.new(0, 0);
let dist = Point.distance(p1, p2);  // 5.0

Format strings

let name = "Alice";
let age = 30;
let items = [1, 2, 3];

println(f"Hello, {name}!");
println(f"Next year you'll be {age + 1}");
println(f"List has {len(items)} items: {items}");

Execution modes

Walrus provides multiple execution modes to suit different workflows:

Script execution

Run Walrus programs directly from files
walrus program.walrus

REPL

Interactive shell for rapid prototyping and testing
walrus

Bytecode mode

Explicit bytecode compilation and VM execution
walrus -c program.walrus

Performance

With the optional JIT compiler enabled, Walrus can achieve dramatic speedups on computational workloads:
BenchmarkInterpreterJITSpeedup
10K iterations × sum(0..1000)0.68s0.01s~68x
JIT compilation requires building with the --features jit flag and is most effective for hot integer range loops.

Get started

Installation

Install Walrus and set up your development environment

Quickstart

Write your first Walrus program in minutes

Language reference

Explore Walrus syntax, data types, and language features

Standard library

Learn about built-in functions and standard library modules

Why Walrus?

Walrus uses a bytecode virtual machine with 80+ opcodes for efficient execution. The VM features proper call frames, tail call optimization, and optional JIT compilation for hot loops using Cranelift.
Walrus syntax is designed to be readable and expressive. Functions use the : param syntax, structs provide static methods, and format strings support embedded expressions.
First-class functions, closures, structs with methods, comprehensive data types, and a rich standard library make Walrus suitable for a wide range of applications.
Walrus is implemented in Rust, leveraging the language’s performance and safety guarantees. The codebase uses modern Rust practices including arena allocation and custom allocators.

Next steps

Ready to start coding in Walrus? Follow our quickstart guide to write your first program:

Quickstart guide

Get up and running with Walrus in under 5 minutes

Build docs developers (and LLMs) love