P
Mellos × Perk

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!
}
    

Why Perk?

C is a relic from the past

Perk builds on C's simple foundation, adding modern features such as option types, type inference, lambdas and typeclasses, while remaining as low level and efficient as C.

C++ is bloated

C++ has all the features Perk will ever have, and a hundred more. In the spirit of C, Perk provides a minimal but powerful feature set, aiming to keep the language compact and easy to learn.

Additionally, unlike C++, Perk does not currently require runtime support.

Rust is not ergonomic

Rust provids strong safety guarantees at the cost of significantly constraining the developer.

This makes it an absolute pain to work with. In Perk, we decided to prioritize the ergonomics of the language. This means safety is not completely guaranteed, but it's still safer than C.

Perk Examples

Option Types

let map : (int -> int) -> void = (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.),

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

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

fun main(): int {
    let but := summon Button((3.14159, 0.12345));
    but.draw();
    banish but;
}
    

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();
}