proto

A language compiler exploring as many parts of compiler theory as we (the writers) can muster

Comments


Basic types


i64: 1, 2, 3, 4
str: "some string"
char: 'a', 'e', 'i', 'o', 'u'
bool: true, false
unit

Complex types (and their type annotations)


    Variables (Mutable and Immutable)

    Code blocks


    Control flow

    Pieces of code can be conditionally executed using if ... else expressions.

    let a = 3;
    let b = 2;
    
    if a > b {
        println("a is greater"); // block returns unit
    } else {
        println("b is greater"); // block returns unit
    }

    Since the if ... else construct is an expression, it can be used in variable definitions (provided the branch blocks don’t return unit like they do in the above example).

    let a = 3;
    let b = 2;
    
    let c = if a > b {
        a * a // returns i64
    } else {
        b * b // returns i64
    };

    The variable c in the above example is inferred to be i64 since that is the type of the if ... else expression.

    The else part of the construct allows further if expressions to check more conditional cases:

    let a = 3;
    let b = 2;
    
    let c = if a > b {
        "a is greater" // returns str
    } else if b > a{
        "b is greater" // returns str
    } else {
        "they are equal" // returns str
    };

    GitHub

    View Github