Skip to content

Example Syntax

Nathan BeDell edited this page Dec 27, 2024 · 2 revisions

Although ef3r is intended to be primarily a novel runtime showcasing various experimental functionality, to make it easier to interact with that runtime, we also define a basic language that compiles to ef3r bytecode.

This has yet to be implemented, but here are some ideas for what a potential syntax for this language could look like:

Potential Syntax

Basically the syntax is OCaml / Rust / Kotlin inspired:

// Possible type annotation syntax?
//
//  let mapped_list : List(Int)
//  where
//    mapped_list = xs.map { x -> x + 2 };
//
// We could possibly also allow for a haskell-style
// where blocks with local visibility.
// We could maybe even omit the "let", and just do
//
//mapped_list : List(Int)
//  = xs.map { x -> x + 2 };
//
// also keeping the "where" syntax optional.

// Case syntax, including a variation on
// "lambda case"
//
//factorial : Int -> Int
//where
//  factorial = { when n ->
//      is 0      => 0
//      otherwise => factorial(n - 1)
//  }
//
// Idea: "let" can be used for exporting. If omitted, a variable is only local
//  / private.

let basic_test = {
    print_ln("Hello, world!")

    let (node, on_update) = new_node(Int, 0)

    assert(node.value == 0)

    on_update(1)

    assert(node.value == 1)
}

let test_2 = {
    let (node, set_node) = new_node(Int, 0)

    assert(node.value == 0)

    let task = launch {
        delay(100)
        on_update(1)
    }

    task.await()

    assert(node.value == 1)
}
Clone this wiki locally