-
Notifications
You must be signed in to change notification settings - Fork 265
Description
The code is basically only lists of consecutive elements. The idea behind this suggestion is to try to only have a more uniform syntax for all of them, to help laziness for users and simplify tooling.
There are basically 3 forms of lists separators in code:
- The in between separator (like the argument/parameter separator)
- The in between separator with an optional trailing separator (like enum declarations)
- The mandatory terminal separator (like statements blocks with some exception)
While these have their purpose, they are separated cases that needs to be learned for each usage. This adds a small cognitive burden and represent a learning curve.
In case of code generations, it means, that we also have to 2 different ways to generate theses lists. A simple/dumb for
loop cannot be used in the case of in between separators, there is always a small exceptions to skip one separator.
For maximum compatibility, I suggest that all the grammatical lists are "in between separator with an optional trailing separator". (The only exception left should be the statements block, since it does "replace" a ;
in most cases).
When writing/generating it adds laziness, and generalize the trend that was introduced with (at least) the enum
case.
Parsing is now a little bit more complex (since there are now always the possibility of a trailing separator). But since the construction is more generalized, vectorization of grammar parsing is even more encouraged.
Since the old macro usage is banned for the future, it should not conflict with that proposition. It was the only usage (that i can think of) that would produce a different number of argument in case of the presence of a blank/empty argument.
The others syntax could be chosen, but they are more strict and does not encourage expressiveness. While the enum
case was most probably to simplify enum
interaction with macros, it shows a trends for users to (de)activate list parts using comments in live coding. When producing diff (like with git), it should/does reduce the noise that would be induced if the in between separator syntax was chosen.
It would allow something like:
doubler: (a: int,) -> (i : int,) = {
i = a * 2;
return
}
main: () -> int = {
grouping := (0, 1, 2,);
array := [0, 1, 2,];
v := vals(21);
v.i
}
While it is not a syntax that I would encourage, in case of diffs it would allow things like (with a specific style format):
myfunction(
a : _,
b : _,
- obsolete_parameter: _
) -> (
i : _,
+ super_important_parameter: _,
) = {
...
}
It should help in some cases to make diffs less busy, ease readability (and therefore help to focus more on what really change).
PS: Sorry to propose a small syntax change. But considering how it can help to simplify the tooling, I think it is worth giving a try.