Pyro

An experimental programming language.

Version 0.3.2

Examples


Fibonacci numbers

Calculate the n-th Fibonacci number:

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

Reading from standard input

Read a single line from standard input:

var line = $stdin:read_line();

Read in a loop from standard input:

loop {
    $print(">>> ");
    var input = $stdin:read_line();

    if input == null || input == "exit" {
        break;
    }

    echo "input was: " + input;
}

Reading a file

Read a file into a byte buffer:

var file = $file("example.txt", "r");
var buffer = file:read();
file:close();

Guessing game

The classic guess-a-random-number game:

var target = $std::prng::rand_int(10) + 1;

loop {
    $print("Enter a number between 1 and 10: ");

    var guess = $stdin:read_line();
    if guess == null || guess == "exit" {
        break;
    }

    if guess == $str(target) {
        echo "Correct!";
        break;
    } else {
        echo "Wrong! Try again...";
    }
}