Zevic 0.0.3: struct, class, enum, Option and Result
v0.0.3 completes the tools for working with data.
struct(value type),class(reference type) andenum(can carry data)match, with guards, ranges and nested patterns. The compiler rejects amatchthat does not cover every caseOptionandResult, and the?operator. Neither is special in the language: the standard library defines them asenumsArray<T>is also written in Zevic itself- Generics (one function is generated per type) and tuples
The design with no exceptions and no null took shape in this version. Failures are return values, and bugs are a Panic.
fn Half(n: I32) -> Result<I32, Error> {
if (n % 2 != 0) {
return Err(Error.New(ErrorKind.Invalid, "${n} is odd"))
}
Ok(n / 2)
}
fn Quarter(n: I32) -> Result<I32, Error> {
let h: I32 = Half(n)?
Half(h)
}