Opus is a programming language prototype.

Express freely. Reason clearly.

Familiar building blocks, explicit intent, and a little mathematical shorthand. Explore the ideas behind Opus through its syntax.

Bindings

Make intent visible.

Use let for a value that stays put and var for one that can change. Types sit beside names, so the shape of your data is clear at a glance. The semantic analyzer checks types and rejects reassignment to immutable bindings.

let startingPoint: Int = 10
var position: Int = startingPoint

// A variable can change.
position = position + 5

// A constant keeps its value.
let scale: Float = 1.5

Arithmetic

A little closer to math.

Add, multiply, group, and go. Familiar operators follow precedence rules, while a postfix ! gives factorial its own place in the language. Constant expressions can be evaluated during semantic analysis, before any runtime is involved.

// Factorial, without a helper function.
let arrangements: Int = 5!

// Familiar arithmetic and grouping.
let total: Int = 3 + 2 * 4
let grouped: Int = (3 + 2) * 4

let remainder: Int = 13 % 3

Control flow

Read the rhythm.

A repeat block puts the action first and its stopping condition at the end. The body runs once before the until condition is considered. Braces give the block its boundaries. Line breaks separate statements, without semicolons.

var number: Int = 0

repeat {
    number = number + 1
} until number == 10

Functions

Give an idea a name.

Function signatures put inputs and outputs in view. Named, typed parameters lead into a return type, with the implementation held in a simple block. At the call site, argument labels keep each value connected to its purpose.

func getLeftHandSide(lhs: Int, rhs: Int) -> Int {
    return lhs
}

let leftHandSide: Int = getLeftHandSide(
    lhs: 10, rhs: 20
)

Explore what’s taking shape.

Opus is a language prototype with a C implementation of lexical analysis, parsing, and semantic analysis. The compiler front end builds an abstract syntax tree and checks a subset of the language’s semantics. Loop and function examples show syntax supported by the parser.