👾 Plum
A simple, statically typed programming language with enums, pattern matching and generics. It compiles to WebAssembly.
import std/Io
import std/Int
import std/Float
import std/Str
import std/List
import std/Option
enum Shape =
| Circle(r: Float)
| Rect(w: Float, h: Float)
fun area(self) -> Float =
match self
Circle(r) => r * r * 3.14
Rect(w, h) => w * h
fun firstEven(xs: List[Int]) -> Option[Int] =
for x := range xs
if x % 2 == 0
return Some(x)
None
fun main(io: Io) =
shape := Rect(w: 2.0, h: 3.0)
even := firstEven([1, 3, 4]).unwrapOr(0)
io.printLn("area {shape.area()}, first even {even}")
test "shapes"
assert Rect(w: 2.0, h: 3.0).area() == 6.0
assert firstEven([1, 3]).isNone()
Features
- Easy to read: blocks are indentation, and there is one way to loop over anything.
- Structs and enums:
matchchecks that you handled every case. - Generics: write
fun id[T](x: T) -> T, and each type gets its own fast copy. - No null, no exceptions: absence is
Option, failure isResult, and?passes an error up. - Closures and tail calls: recursion runs in constant stack.
- Tests built in: add a
testblock next to your code and runplum test. - Visible side effects: printing, files and network go through an
Iovalue, so a function without one can't touch the outside world. - Fast by default: the compiler removes temporary lists and updates values in place when it is safe, with no change to what your code means.
- Games: a built-in engine runs in the browser on WebGPU.
- Editor support: syntax highlighting and a language server for Helix and VSCode.
Plum compiles to WebAssembly (wasm-gc), and plum build wraps the result in a native executable. True native targets are planned.
Install
| Platform | Download |
|---|---|
| macOS (Apple Silicon) | plum-darwin-arm64 |
| Linux (x86_64) | plum-linux-x86_64 |
| Windows (x86_64) | plum-windows-x86_64.exe |
Make it executable and put it on your PATH, e.g. on macOS/Linux:
curl -L -o plum https://git.pyrossh.dev/releases/plum-cli/v0.1.0/plum-darwin-arm64
chmod +x plum
mv plum ~/.cargo/bin/plum # or anywhere else already on your PATH
Or build from source with cargo install --path compiler/cli.
Use it
Run these from a checkout of this repository, so import std/... can find the standard library.
plum run file.plum # compile and run; a game opens in the browser and reloads as you edit
plum test file.plum # run its tests
plum build file.plum # make an executable, or a website for a game
plum editor helix # set up your editor (or vscode)
Learn more
- The language: the full guide
- The standard library: strings, lists, maps, JSON, files and more
- The game engine: drawing, input, sound and scene graphs
- Tools: every command and option, editors, building from source
- Performance: how the compiler optimises your code
- Examples: a runnable file per feature, and example games