Scarlet Industries

The Scarlet language

A statically-typed and expression-oriented programming language. Source files end in .scrl.

import scarlet/array

type Shape {
	Circle(r Float)
	Rect(w Float, h Float)
}

fn area(s Shape) Float {
	match s {
		Circle(r) -> 3.14159 * r * r
		Rect(w, h) -> w * h
	}
}

pub fn main() {
	shapes = [Circle(r: 2.0), Rect(w: 3.0, h: 4.0), Circle(r: 1.0)]
	println('total area: ${array.fold(shapes, 0.0, fn(acc, s) acc + area(s))}')
}

Install

Install the binary. The script places it in ~/.scarlet/bin and adds that directory to your shell's path.

curl -fsSL scarlet.industries/install.sh | bash

Run

Write a file. Run it. A program starts at pub fn main(); module scope holds declarations — imports, types, functions, constants — and no statements.

// Hello world, plus string interpolation with ${}.

pub fn main() {
	println('hello, world')

	name = 'Scarlet'
	println('hello from ${name}')
	println('2 + 2 = ${2 + 2}')
}
scarlet run hello.scrl
Command Function
scarlet run <file> [args] Run a program. Trailing arguments reach the program through os.argv
scarlet check <file> Type-check a program without running it
scarlet fmt [path] Format source files in place. --check exits 1 on unformatted files
scarlet repl Start an interactive REPL session
scarlet lsp Start the language server
scarlet dis <file> Print the compiled bytecode. --native prints the native code the JIT produced beside it
scarlet man Emit the manual page to stdout
scarlet upgrade [version] Replace the binary with a named version. The default channel is canary

Programs compile to bytecode and run on a virtual machine with a JIT. A call in tail position reuses the current stack frame, so recursion runs flat, mutual recursion included.

Chapters

The reference is one page per topic. Read it in order, or go straight to the one you need.