Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax snags for new users #385

Open
aiverson opened this issue Jul 22, 2019 · 9 comments

Comments

@aiverson
Copy link

commented Jul 22, 2019

While getting some new people to learn terra and expanding projects in terra, I'm finding bits of syntax that are difficult and confusing to read and write, especially for new users.

One example of this is a splice in an array index. This introduces a syntax collision and produces a confusing error message. Because arr[[expr]] parses as a string call, it gives an error message that is nonobvious and doesn't help fix it. However, in a common case for implementing __entrymising with self[ [ fieldmap[entryname] ] ]the nesting of square brackets inside them selves is even more difficult.

Changing the brackets for a splice to |expr| would make this less confusing, and was suggested to me by one new user.

I'm opening this issue to collect a list of similar syntax snags and to discuss mitigating them by some combination of improving documentation, improving error messages, and changing syntax.

@blackhole12

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2019

An alternative syntax might be {{expr}}, which is similar to the action syntax in Go templates, which is basically the same thing as an escape in Terra.

@aiverson

This comment has been minimized.

Copy link
Author

commented Jul 24, 2019

That conflicts with constructing a tuple or anonymous struct.

@elliottslaughter

This comment has been minimized.

Copy link
Collaborator

commented Jul 24, 2019

We should have (in a separate issue, not this one) a discussion on what our backwards compatibility story is going to be. I'm torn on issues like these because they are paper cuts, but they also require backwards compatible changes (unless you propose to maintain two syntaxes, which is not without cost either).

@DarkWiiPlayer

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2019

Since [exp] clashes with indexing and {exp} with tuple creation, my next idea would have been $(exp), which is a familiar syntax to (ba|z|.*)sh users, where it's already used for a sort of "multi stage" scripting (The output of one command becomes part of another command) and it wouldn't clash with any other Lua or Terra syntax.

Since $ isn't used anywhere else, a shorter version $exp could even be added for certain simple expressions.

Another option that should be mentioned, though I personally find it extremely ugly is `exp` as in Bash or Ruby.

@elliottslaughter

This comment has been minimized.

Copy link
Collaborator

commented Aug 1, 2019

I believe $exp is always unambiguous because exp must always be an expression (i.e. $exp $exp can be parsed unambiguously as $exp; $exp). Someone please correct me if I'm wrong about this. Of course $(exp) will be valid because (exp) is just a parenthesized expression.

The other option `exp` doesn't work because `exp is already the expression quote operator in Terra.

There is still the issue of having two syntaxes for the same thing though.

@DarkWiiPlayer

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2019

what about $a + b though? is that $(a + b) or ($a) + b? I'd say it should be the second one (so the rule would be use to stop as soon as there's a valid expression), and if you wanted the first you should have to write the braces explicitly.

@elliottslaughter

This comment has been minimized.

Copy link
Collaborator

commented Aug 1, 2019

You'd have to pick the precedence, just like unary - and the ` operator. Probably I'd look at the latter to see what has been done so far. (I don't remember off the top of my head what the precedence of ` is.)

@OvermindDL1

This comment has been minimized.

Copy link

commented Aug 1, 2019

In every other language I can think of, the precedence would be ($a) + b.

@aiverson

This comment has been minimized.

Copy link
Author

commented Aug 1, 2019

This also has a natural extension to basic string splicing, making a parallelism between splicing in a tree quote and splicing in a string quote. PHP made this syntax look terrible to me, but it does make sense.

And as for precedence and implementation. I'd just make it a prefix expression just like # which I believe accomplishes the desired goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.