Skip to content

v0.9.0

Compare
Choose a tag to compare
@huacnlee huacnlee released this 15 Nov 07:15
· 10 commits to main since this release
7b15171

Language

  • Add interface support.
  • Add navi fmt to format code, and install the VS Code extension.
  • Add loop statement to loop forever.
  • Add getter, and setter to built-in type.
  • Add dotenv support, now will auto load .env file in the current directory as environment variables.
  • Add if let statement.
  • Add main function, now navi run will run the main function in main.nv file in default.
  • Add httpbin feature into testharness to speedup HTTP test.

Stdlib

  • Add resize, truncate, split_off, chunks method to array.
  • Add weekday to std.time.
  • Add std.process with exit, abort, pid, exec, run, args function.
  • Add std.json, std.yaml, std.querystring modules for JSON, YAML, QueryString parse, and stringify.
  • Add std.value module to common value type.
  • Add basic_auth method to HTTP Request.
  • Add chunk method to HTTP Response.
  • Add multipart, form, timeout to http.Request.
  • Add read, read_string to fs.File, and read, read_string to fs module.
  • Add std.io.stdin, std.io.stdout, std.io.stderr.
  • Add join to std.url.
  • Add std.env.vars to get all vars.

Breaking Changes

  • Rewrite string interpolation from {1 + 2} to ${1 + 2} like JavaScript.
  • Kw Arguments now use : instead of =, e.g.: fn(a: 1, b: 2), no longer allowed to be passed positionally.
  • Most struct get method in stdlib now is getter, e.g.: host instead of host() for url.URL.
  • Rename fs.read_string to fs.read_to_string.
  • Rename io.from_bytes to io.new_bytes_from_array.
  • Move cwd, chdir from std.path to std.env.

Examples

Interface

Like Go, you can define an interface in the following way:

interface Readable {
    fn read(): string
}

fn read(r: Readable): string {
    return r.read()
}

struct File {
    path: string
}

impl File {
    fn read(): string {
        return "read file"
    }
}

struct Body {
    content: string
}

impl Body {
    fn read(): string {
        return "read body"
    }
}

fn main() {
    file := File{path: "file"}
    body := Body{content: "body"}
    println(read(file))
    println(read(body))
}

If let

use std.io;

fn main() {
    let name: string? = "Navi";

    if let name = name {
        io.println("name is ${name}")
    } else {
        io.println("name is nil");
    }
}