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

Wrong precedence for unary minus or pow #2250

Open
bsansouci opened this issue Oct 27, 2018 · 4 comments
Open

Wrong precedence for unary minus or pow #2250

bsansouci opened this issue Oct 27, 2018 · 4 comments
Labels
Parser parsing reason code into an AST

Comments

@bsansouci
Copy link
Contributor

let a = -. x ** 2.;

parses as

let a = (-. x) ** 2.;
@bsansouci bsansouci changed the title Wrong precedence for unary minus Wrong precedence for unary minus or pow Oct 27, 2018
@IwanKaramazow
Copy link
Contributor

To what extend do you think that we should change this?
For example in JS, this is the expected precedence:
image

@strega-nil
Copy link

@IwanKaramazow no matter how that is parsed, that will result in the same number.

I would also argue that this is not incorrect - postfix operators should bind tighter than prefix operators, which should bind tighter than any binary operators.

@bsansouci
Copy link
Contributor Author

bsansouci commented Oct 31, 2018

screen shot 2018-10-30 at 9 03 20 pm

EDIT:
Mmmmmmh... Honestly I think the intuition would be that the minus isn't lumped into the x^2. In math you'd write something like x^3 - x^2 - x - 1 for example. All the - aren't lumped into the expressions, the exponentiation takes precedence. So I think ideally we'd do that. If you guys disagree maybe we could make it a parse error, so that I would at least be able to fix it immediately and move on.

@jaredly
Copy link
Contributor

jaredly commented Oct 31, 2018

In [1]: -2**2
Out[1]: -4

python does what you expect @bsansouci

@anmonteiro anmonteiro added the Parser parsing reason code into an AST label Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Parser parsing reason code into an AST
Projects
None yet
Development

No branches or pull requests

5 participants