Pyro

A scripting language for people who enjoy the simpler things in life.

Version 0.9.35

Conditional Scoped Variables



Pyro supports conditional-scoped variable declarations inside if statements, e.g.

if var value = get_value(); value != null {
    $println("value = {}", value);
}

Here, value is a new local variable valid inside the scope of the if statement, including any else if or else clauses, e.g.

if var number = get_number(); number > 1000 {
    $println("very big number: {}", number);
} else if number > 100 {
    $println("big number: {}", number);
} else {
    $println("small number: {}", number);
}

Syntax

The syntax is:

if var <variable-declaration>; <expression> {
    ...
}

The code inside the if block will be executed if <expression> is truthy.

Unpacking

You can use variable-unpacking syntax inside an if statement, e.g.

if var (x, y) = get_location(); x == 1 && y == 2 {
    echo "correct location";
} else {
    echo "incorrect location";
}

Here, x and y are new local variables valid inside the scope of the if statement, including any else if or else clauses.