The Vale Programming Language

Patterns are a convenient, concise syntax for receiving some incoming data and doing some common things with it. Keep reading to see how.

Patterns Make Locals

We use patterns to make new locals.

Everything to the left of an = is a pattern.

The pattern on the left receives incoming data from the expression on the right.

To the left of this = is a pattern that stores the incoming data into a local named a.


fn main() export {
a = 3 + 4;


If we're receiving a struct, we can destructure the incoming struct and put its members into locals.

In this example, we're taking the parts of the Vec3 and assigning them into locals a, b, c.


struct Vec3 imm {
x int;
y int;
z int;

fn makeVec() Vec3 { Vec3(3, 4, 5) }

fn main() export {
// Without destructure pattern:
tempVec = makeVec();
a = tempVec.x;
b = tempVec.y;
c = tempVec.z;

// Equivalent, using destructure:
Vec3(d, e, f) = makeVec();

// Equivalent; can leave off the type:
(g, h, i) = makeVec();

println("a: " + a);
println("d: " + d);
println("g: " + g);
a: 3 d: 3 g: 3


Every parameter is a pattern.

Here, we're using destructuring for this function's parameters.

// Using above Vec3

// Without destructuring:
fn refuel(
vec Vec3,
len float)
vec.x * len,
vec.y * len,
vec.z * len)


// With destructuring:
fn refuel(
Vec3(x, y, z),
len float)
Vec3(x * len, y * len, z * len)

Planned Features

These are planned features for Vale. See the roadmap for plans!

Match Statement

We can use a pattern to check if the incoming data is a certain value.

Here, we're using a match statement to check what the user entered.

In patterns, _ matches any incoming data and discards it.

fn main() export { mat inputInt() { 1 { println("One!"); } 2 { println("Two!"); } _ { println("Other!"); } } }

We can even check an incoming interface, to see what substruct it is.

We can even destructure it at the same time!

interface ISpaceship { } struct Firefly { name str; } impl ISpaceship for Firefly; struct Raza { name str; fuel int; } impl ISpaceship for Raza; fn main() export { serenity = Firefly("Serenity", 2); mat serenity { Firefly(name) { println("Firefly name " + name); } Raza(name, fuel) { println("Raza name " + name); } } }
Firefly name Serenity

Next: Regions