Syntax discussion -- should we overhaul the syntax? #247
Replies: 5 comments
-
Idea 1 -- unified call syntaxThe whole thing with poly parens and normal parens is ugly. Instead, we could just use parens. Also, for consistency, we could use parens for constructors. Then, we could determine whether it's a typefunc call, a function call, or a constructor call using unification during metacheck. letters : array(string()) = make_array(5, "A"); Drawbacks:
func := make_array(string()); // this is a function from (int, string) to array of string
value := make_array(5, "A"); // this is an array of string
also_value := make_array(string())(5, "A"); // this is an array of string Alternative -- bracket typefunc callsIf we use brackets ( func := make_array[string[]]; // this is a function from (int, string) to array of string
value := make_array(5, "A"); // this is an array of string
also_value := make_array[string[]](5, "A"); // this is an array of string Consequence 1If we use parens for constructors, there is no way a block statement can get confused by the arguments to a constructor. Thus, we could omit parens from if-else statements (and others, too). |
Beta Was this translation helpful? Give feedback.
-
Idea 2 -- do-end style blocksI don't like these, but maybe you do. I got the idea from Ruby. fib := fn (n) do
a := 0;
b := 1;
while (n != 0) do
sum := a + b;
a = b;
b = sum;
end
return a;
end; |
Beta Was this translation helpful? Give feedback.
-
Idea 3 -- different / shorter functionsNow that we have more experience with parsing, we can afford neater function expressions // idea 1
sum := |x, y| x + y;
// idea 2
sum := (x, y) => x + y;
// idea 3
sum := fn (x, y) = x + y;
// idea 4
sum := fn (x, y) x + y; |
Beta Was this translation helpful? Give feedback.
-
Idea 4 -- get rid of colonsIn pretty much every place where they appear by themselves, colons could be easily removed, and be replaced by whitespace. version string<::> := "v1.0.36";
sum := fn(x int<::>, y int<::>) => x + y;
pair := struct {
first int<::>;
second int<::>;
}; |
Beta Was this translation helpful? Give feedback.
-
Idea 5 -- Use semicolons instead of commas in function callsAfter writing a bit of Jasper code, I found myself doing this refactor quite often: // before:
x := foo<::> { expr1; expr2; expr3; };
y := foo<::> { expr4; expr5; expr3; };
// after:
make_foo := fn(value1, value2) => foo<::> { value1; value2; expr3; };
x := make_foo(expr1, expr2);
y := make_foo(expr4, expr5); I noticed that changing semicolons to commas, removing spaces, and, to a lesser degree, replacing braces for parens, was really annoying. I propose changing comas to semicolons in function calls, and allowing a trailing semicolon on the argument list. Also, we should pick a stance on spaces around parens. Whether we should change the constructor and call argument delimiters (namely braces and parens) is a separate discussion. (see Idea 1) // before:
x := foo<::> { expr1; expr2; expr3; };
y := foo<::> { expr4; expr5; expr3; };
// after:
make_foo := fn(value1, value2) => foo<::> { value1; value2; expr3; };
x := make_foo ( expr1; expr2; );
y := make_foo ( expr4; expr5; ); Thoughts? @lushoBarlett |
Beta Was this translation helpful? Give feedback.
-
The parser, and the current (concrete) syntax both have a number of issues that need addressing. I propose a parser rewrite, accompanied with a syntax overhaul.
This thread is so we can talk about it, and come up with some ideas for how it could look like.
I will start by proposing a few different things, then we can discard them, and add new ones, as we go.
Beta Was this translation helpful? Give feedback.
All reactions