I'm trying to figure out a nice way to do lists in F++ while not requiring commas as separators and also taking advantage of the difference between \n and " " to avoid a layer of parens. By lists I really mean function argument lists and elements (I won't call them statements) in blocks of code. It seems like I should be able to make \n mean "next item in implicit list" but it's a bit tricky figuring out which list is the implicit list. Below are some examples of what I'd like to be able to write and what I'd like it to be equivalent to.
With whitepsace | Explicit | Notes |
---|---|---|
f 1 2 3 | f(1, 2, 3) | Nothing special. |
f(1 g 2 3 4) | f(1, g(2, 3), 4) | The \n at the end of the "g" line terminates the g() function call and moves us onto the next argument for f(). |
{ x = f 1 y = f 1 2 3 z = f 1 2 \ 3 w = f g 2 3 v = f g 2 3 } | { x = f(1); y = f(1, 2, 3); z = f(1, 2, 3); w = f; # still not sure if that's f or f() g(2, 3); v = f; g(2, 3); } | Here the "z" line uses \ for continuation and so the \n is treated as just as list-separator space. The "w" line does not grab the "g". Neither does the "v" line because indentation is irrelevant!. |
So what rules will result in parsing the above the way I want? Perhaps any explicitly delimited list containing a raw \n (ie not preceded by \) gets treated as 1 element per line and that's that. Or I could make function calls special. I think that's mainly where the fun is. Since they always start with a symbol, you know when you've encountered a function and if the symbol isn't followed by "(" then it ends at the next raw "\n". I can say a function call is symbol "(" args* ")" # separated by any kind of whitespace or symbol args* # separated by any whitespace except raw \n