Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Started

Installation

You can install Oxynium on any Linux/MacOS system by running the following command in your terminal:

curl -sSL https://oxynium.org/scripts/install | bash

Unstable version

You can also install the latest version by passing the latest argument to the installation script.

curl -sSL https://oxynium.org/scripts/install | bash -s -- latest

Requirements

Oxynium will require cargo, rust, nasm and gcc to be installed on your system.

Upgrade

To upgrade to the latest version of Oxynium, run the installation script:

curl -sSL https://oxynium.org/scripts/install | bash

Uninstallation

You can uninstall Oxynium by running the following command in your terminal:

curl -sSL https://oxynium.org/scripts/uninstall | bash

Examples

These are a few simple examples which showcase some of the language's features.

Hello, World!

print("Hello, World!")

Fibonacci

const N = 10;

def fib (n: Int) Int {
    if n <= 1 {
        return n;
    }
    return fib(n - 1) + fib(n - 2);
}

print(fib(N).Str()); // 55

FizzBuzz

def main() {
    for i in range(100) {
        print(fizzbuzz(i));
    }
}

def fizzbuzz (n: Int) Str {
    if n % 3 == 0 && n % 5 == 0 {
        return "FizzBuzz";
    }
    if n % 3 == 0 -> return "Fizz";
    if n % 5 == 0 -> return "Buzz";
    return n.Str();
}

Generic classes

class LoggedQueue<T> {
    backing_list: List<T>,
    
    def make_empty<S>()
        -> new LoggedQueue<S> { backing_list: List.empty!<S>() },
    
    def push(self, item: T) LoggedQueue<T> {
        self.backing_list.push(item);
        print("added item " + self.len().Str());
        return self;
    }
    
    def pop(self) T {
        if self.len() < 1 -> panic("pop on empty list");
        let val = self.backing_list.remove_at(0).unwrap();
        print("popped item " + self.len().Str());
        return val;
    }
    
    def len(self) ->
        self.backing_list.len()
}

def main() {
    let q = LoggedQueue.make_empty!<Int>()
                       .push(5)
                       .push(6);
    
    print("process: " + q.pop().Str()); // 5
    print("then: " + q.pop().Str()); // 6
}

Functions

def my_function (param: Int) Int {
    return param * 9
}

equiv to

let my_function = fn (param: Int) -> param * 9

Note that let can only be used inside a function definition, so this definition cannot be used at the top level

Classes

class MyClass {
    name: Str,
    
    def my_instance_method(self) {
        print("hi from " + self.name)
    }
    
    def my_static_method() {
        // no access to 'name' from here
        print("hi from MyClass")
    }
}

Primitives

Primitives are like classes, except they can only hold one 64-bit value, and are not stored as a reference.

There are several built-in primitives: Int, Char, Bool, Ptr.

Other primitives generally should not be created: instead use classes.

primitive MyPrimitive {
    // cannot declare fields on primitives,
    // only methods and static methods
    
    def do_something(self) {}
    def something_static() {}
}