Perk

A modern, ergonomic, low level programming language.

From the devs of MellOS, designed with the goal of providing a better language for writing operating systems and scientific applications.

Perk is an open source project, and it is still in development.

fun main(): int {
    printf("Hello, World!\n");

    // type inference
    let pi := 3.1415;

    // option types
    let x: float*? = nothing;
    x = just π

    // lambdas
    let area: float => float = (r: float) : float {
        return pi * r * r
    };

    // ...and more!
}
    

Perk Examples

Option Types

fun map (f: int => int) : void {
    if (self.v?) {
        self.v = some(f(self.v!));
    };

    if (self.next?) {
        let next_node: List = self.next!;
        next_node.map(f);
    }
}
    

Models

model Test {
    let str: char* = "Hello, World!"
}

fun main(): void {
    let test := summon Test();
    test.str = "Hello, Universe!";
    printf(test.str);
    banish test;
}
    

Typeclasses (Archetypes)

archetype Drawable {
    pos : (float * float),
    draw : () -> void
}

model Button : Drawable {
    let pos : (float * float) = (0., 0.),

    fun constructor(pos: (float * float)) : void {
        self.pos = pos
    },

    fun draw() : void {
        printf("drawn at position (%f, %f)\n", self.pos[0], self.pos[1]);
    }
}
    

Functional Features

fun is_prime(n: int) : int {
    if (n < 2) {
        return 0
    };
    let i := 2;
    while (i < isqrt(n) + 1) {
        if (mod(n, i) == 0) {
            return 0;
        };
        i++;
    };
    return 1;
}

fun main(): int {
    let nums := list_from_range(10);
    // higher order function application!
    nums.filter((a: int) : bool => {
        is_prime(a)
    });
    nums.print();
}