Skip to content

Repository files navigation

CIZigLicense

Syntax

Variables

// All types are in PascalCase: Int, Float, Bool, String, etcvara: Int=1// explicit typevarb=2.5// type inferenceconstname="Bob"

Functions

fnadd(a: Int, b: Int) Int {
returna+b;
}

Control flow

// if statementifa>b {
print("a is greater than b");
}
// if as an expressionvarmax=ifa>b { a } else { b };
print("The max is $max);// when (pattern matching)when a { 1 => print("ais1"); 2 => print("ais2"); else => print("aisnot1or2");}

Error handling

// Declare an error typeerrorMathError { DivByZero, Overflow }
// Fallible function: returns MathError!Int or !Int (inferred)fndivide(a: Int, b: Int) MathError!Int {
ifb==0 { returnMathError.DivByZero }
returna/b;
}
// try propagates the error up (caller must also be fallible)fnsafeDivide(a: Int, b: Int) !Int {
returntrydivide(a, b);
}
// catch handles it inlineconstresult=divide(10, 0) catch { -1 };
// catch with bindingconstresult=divide(10, 0) catche { print(e); -1 };
// one-liner catch with bindingconstresult=divide(10, 0) catche=>-1;
// Untyped error with a messagefnlookup(id: Int) !String {
returnfail("not found");
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages