Kavun (кавун, watermelon) is a lightweight, high-performance, embeddable scripting language for Go, built around expression-oriented programming and consistent language design principles. Its feature set, including f-strings, arrow-function lambdas, data-type member functions, and fluent chaining, enables transformation-heavy code to be written as clear expressions instead of loop-and-branch boilerplate. It runs on a bytecode VM implemented in Go, making embedding and sandboxing straightforward in Go services and tools.
- Dynamically typed, with coercive equality (
1 == "1") and a small, predictable truthiness table. - Expression-oriented — arrow lambdas (
x => x * 2), fluent method chaining,if/forinit statements sharing scope with their block. - Destructuring & parallel assignment —
a, b = b, a,a, b, c = [1, 2, 3],a, b = {a: 1, b: 2}. - Placeholder syntax (
_) —add(1, _, 3)is sugar forx => add(1, x, 3); see the cheat sheet. - f-strings & runtime format templates —
f"n={n:5d}", plusformat(template, args)for the same{...}/format-spec syntax at runtime. decimalas a first-class type — exact arithmetic for money, not a float workaround.defer/recover— Go-style cleanup and error handling without Go panics on the hot path.- Non-mutating by default — collection methods return new values;
_in_placeandimmutable()are the explicit opt-ins. - Deterministic, single-threaded, sandboxable — no goroutines/channels exposed to scripts, so embedding in finance, decisioning, and game-logic hosts stays reproducible and auditable.
- AST-level optimizer — purity-driven constant folding and dead-code elimination (see purity contract).
Install the cli with Go's toolchain:
go install github.com/jokruger/kavun/cmd/kavun@latestOr download a prebuilt binary from the latest release:
Then you can run Kavun scripts with the kavun command or using hashbang:
#!/usr/bin/env kavun
fmt = import("fmt")
result = [1, 2, 3, 4, 5, 6]
.filter(x => x % 2 == 0)
.map(x => x * x)
.reduce(0, (sum, x) => sum + x)
fmt.println(f"sum of even squares: {result}")See more examples, or the cheat sheet for a one-page syntax reference.
Full benchmark results are available in the Kavun Benchmarks report. A summary is shown below:
| Rank | Engine | CPU geomean | Avg rank | Worst ratio | Wins | Mem geomean | Tasks run | Missing |
|---|---|---|---|---|---|---|---|---|
| 1 | kavun | 1.01× | 1.11 | 1.05× | 8 | 1.04× | 9 | 0 |
| 2 | gopherlua | 1.59× | 2.78 | 4.87× | 1 | 180.03× | 9 | 0 |
| 3 | golua | 1.61× | 3.33 | 2.35× | 0 | 251.53× | 9 | 0 |
| 4 | starlark | 2.55× | 4.22 | 5.17× | 0 | 174.88× | 9 | 0 |
| 5 | tengo | 3.15× | 4.33 | 69.56× | 0 | 1296.87× | 9 | 0 |
| 6 | goja | 5.16× | 6.22 | 10.85× | 0 | 327.41× | 9 | 0 |
| 7 | risor | 6.32× | 6.00 | 230.43× | 0 | 3416.20× | 9 | 0 |
- Installing - Instructions for installing the Kavun CLI.
- Embedding - Guide to embedding the Kavun runtime in Go applications.
- Language Reference - Syntax, expressions, statements, functions, modules, built-ins, and diagnostics.
- Cheat Sheet - One-page quick reference for syntax and key language features.
- Type Reference - Detailed builtin type semantics, conversions, and member functions.
- Standard Library - Overview of standard library modules and their APIs.
- Examples - Short, runnable snippets showcasing key language features.
- Virtual Machine - Virtual machine specifics and limitations.
- Coding Conventions - Guidelines for code style and contributions.
Before contributing, please review docs/conventions.md for project layout, coding standards and
repository contracts.
- Fork the repository and clone your fork locally.
- Make your changes in a focused branch.
- Run the test suite.
- Add or update tests in
tests/unitfor any change that affects language or runtime behavior. - Open a pull request describing the motivation for the change and any new or changed semantics.
This project is licensed under the MIT License. See the LICENSE file for details.
This project is based on script language Tengo by Daniel Kang. A special thanks to Tengo's creator and contributors.