← Blog

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) and enum (can carry data)
  • match, with guards, ranges and nested patterns. The compiler rejects a match that does not cover every case
  • Option and Result, and the ? operator. Neither is special in the language: the standard library defines them as enums
  • Array<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)
}