cda-group / arc

Programming Language for Continuous Deep Analytics
https://cda-group.github.io/arc/
44 stars 6 forks source link

RFC: Python-style syntax #329

Closed segeljakt closed 1 year ago

segeljakt commented 3 years ago

This is just a test too see what the syntax of arc-script would look like if we used Python style indentation. In this case we never need a semicolon. Newline essentially replaces the semicolon. Statements (such as if) may not be expressions, but I'm not sure.

Function declarations

# Current
def foo(x: i32, y: i32): i32;

# New
def foo(x: i32, y: i32): i32

Function definitions

# Current
def foo(x, y) {
    x + y
}

# New
def foo(x, y):
    x + y

Tasks

# Current
task Foo(x: i32): i32 -> i32 {
    on event => emit event + 1
}

# New
task Foo(x: i32): i32 -> i32:
    on event: emit event + 1
# Current
task Bar(x: i32): i32 -> i32 {
    on event => {
        val x = event + 1;
        emit x;
    }
}

# New
task Bar(x: i32): i32 -> i32:
    on event:
        val x = event + 1
        emit x
# Current
task Baz(x: i32): (A(i32), B(i32)) -> i32 {
    on {
        A(x) => emit x,
        B(x) => emit x,
    }
}

# New
task Baz(x: i32): i32 -> i32:
    on:
        A(x): emit x
        B(x): emit x

Lambda expressions

# Current
val foo = fun(x, y): x + y;

# New
val foo = fun(x, y): x + y
# Current
val foo = fun(x, y): {
    val z = x + y;
    z * 2
};

# New
# Not possible (May only have a single statement)

If-expressions

# Current
val y = if x < 0 { 1 } else { 2 }

# New
val y = if x < 0 then 1 else 2
# Current
if x < 0 {
    1
} else {
    2
}

# New
if x < 0 then:
    1
else:
    2
# Current
val y = if x {
    1
} else {
    2
};

# New
val y = if x then:
    1
else:
    2

Traits

# Current
trait Foo[T] {
    def baz(): T;
}

# New
trait Foo[T]:
    def baz(): T

Instantiations

# Current
inst[T] Foo[T] {
    def baz(): T;
}

# New
inst[T] Foo[T]:
    def baz(): T