-
Notifications
You must be signed in to change notification settings - Fork 1
Exploration: Reduced Syntax
The proposal in this document is merged.
Similar to golang, parentheses can be removed around expressions and around some statements.
if (x) {}
# becomes
if x {}
for (x = 0; x < 10; x = x + 1) {}
# becomes
for x = 0; x < 10; x = x + 1 {}
while (x) {}
# becomes
while x {}
# etc.
This is mostly backwards-compatible. for loops will break, as they contain statements rather than expressions. In all other cases, the syntax is still valid, as (x) == x.
A function that returns a tuple does not need to explicitly define a tuple literal.
func tuple<x, y, z>:foo() {
var a = first();
var b = second();
var c = third();
return [:a, b, c];
# becomes
return a, b, c;
}
The return statement will be modified in the parser to search for commas and automatically construct a tuple literal. Functions that return 1-tuples will need to use the following syntax:
return a,;
The comma distinguishes a return statement that returns a tuple already. Consider the following code:
return [: a]; # returns [: a]
return [: a],; # returns [: [: a]]
One can assume that [: a] is replaced with any expression that results in a tuple.