-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
The |>
operator can cause parsing errors where normal function calls do not
#549
Comments
A smaller example with a similar problem:
The problem is that
But maybe precedence should be changed to allow for this? I guess if we would do that, it would prevent us from doing things like
and we would have to put the conditional into parens:
which defeats the initial purpose of this operator (that you can always just add it at the end of a line to do an additional function call) |
Unrelated: I'm excited about this |
Oh of course, I completely forgot about that. I'm not sure of which is better, but perhaps a terminating token to the if-else expression would solve some of the problem? My thinking is that the then clause is already delimited by the else, making it a logical unit to scope as if in parentheses. If the else clause could be delimited as well it would also have an easy to parse scope. It does bring other challenges but it would disambiguate a pipe after the whole statement as if it's after the delimiter it would apply to the whole if-else expression while if inside it applies to only that scope. My main argument against this approach would probably be changing if-else expressions would become ugly or reintroduce ambiguity.
|
I really liked the idea of it when I read about it, so I'm excited to try my hand at it! |
I think that reasoning is correct.
Indeed :-/
what do you mean by that? |
I meant that making a chain of if-else expression would no longer be possible without nesting them. I've had an idea about this. Could the syntax of the if-else be extended? To my understanding the current syntax is something like the following. IfElse = "if" Cond "then" Expr "else" Expr What if chaining was an actual part of the syntax and all chains had to end with a terminating token. Something like the following. IfElse = "if" Cond "then" Expr "else" Expr ; Regular if-then-else
IfElseChain = 1*IfElse "end" ; A chain of one or more if-then-else's terminated with a single "end" token I'm thinking this allows for an optional end token for the normal case that could be used to make the parsing of the pipe operator unambiguous and making the nesting of if-then-else chains easier to determine. As far as I can see it would allow for the current syntax in all cases but enable additional uses without the need for parentheses or many ugly terminating tokens. Disclaimer: I do not really understand the current implementation of the expressions. I have never used Rust and can't really gauge how big of an undertaking this would be, so if it is a larger change then I don't mind the parentheses that much, but would probably write a paragraph about it in the documentation. |
I have continued working on the list representation of mixed units and came upon this odd behavior. In my function, inside an if expression, calling a function with two arguments worked fine, but piping in one of the gave an error. This seems unintentional since I see no reason why it would make it ambiguous.
Below is the two function definitions and their output.
I tested it in the online terminal (wasm) from firefox.
The text was updated successfully, but these errors were encountered: