Skip to content

Exploration: Reduced Syntax

Matt Basta edited this page Mar 3, 2015 · 2 revisions

The proposal in this document is merged.

Eliminate parentheses on control flow

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.

Compatibility

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.

Implied return tuples

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.

Clone this wiki locally