Introduce single line function declaration
Variant 1:
// Statement
fn int square(int x) = return x * x;
fn void foo(int y) = baz(y);
Proposal 2:
fn int square(int x) = x * x;
fn void foo(int y) = baz(y);
Feel free to vote on this one using 👍 and 👎
Proposal 3:
fn int square(int x) {x * x};
fn void foo(int y) {baz(y)};
Proposal 4:
fn int[2] square(int x) (x * 2, x * 3);
3 is ambiguous. 4 would need special parsing.
An alternative uses =>
fn int square(int x) => return x * x;
fn void foo(int y) => baz(y);
fn int square(int x) => x * x;
fn void foo(int y) => baz(y);
Proposal 6: :smile:
fn int square(int x) -> return x * x;
I'm trying to reserve "->" in case it's needed later, plus the problem of that operator when converting C code.
Two variants are now available for test:
fn int square(int x) = x * x;
fn int square(int x) => x * x;
See if it actually adds any value or we remove it.
= is more likely to be adopted than =>
Would single line functions also work for anonymous functions?
@tommy-mitchell They already do.
=> was chosen.