Skip to content

synapticvoid/pipe-lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CI Zig License

Syntax

Variables

// All types are in PascalCase: Int, Float, Bool, String, etc
var a: Int = 1   // explicit type
var b = 2.5      // type inference
const name = "Bob"

Functions

fn add(a: Int, b: Int) Int {
    return a + b;
}

Control flow

// if statement
if a > b {
    print("a is greater than b");
}

// if as an expression
var max = if a > b { a } else { b };
print("The max is $max);

// when (pattern matching)
when a {
    1 => print("a is 1");
    2 => print("a is 2");
    else => print("a is not 1 or 2");
}

Error handling

// Declare an error type
error MathError { DivByZero, Overflow }

// Fallible function: returns MathError!Int or !Int (inferred)
fn divide(a: Int, b: Int) MathError!Int {
    if b == 0 { return MathError.DivByZero }
    return a / b;
}

// try propagates the error up (caller must also be fallible)
fn safeDivide(a: Int, b: Int) !Int {
    return try divide(a, b);
}

// catch handles it inline
const result = divide(10, 0) catch { -1 };

// catch with binding
const result = divide(10, 0) catch |e| { print(e); -1 };

// Untyped error with a message
fn lookup(id: Int) !String {
    return fail("not found");
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors