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

X +Y gets compiled to X(+Y) #2686

Closed
Kambis opened this issue Jan 28, 2013 · 8 comments
Closed

X +Y gets compiled to X(+Y) #2686

Kambis opened this issue Jan 28, 2013 · 8 comments

Comments

@Kambis
Copy link

Kambis commented Jan 28, 2013

Some expression of the type X +Y like
Math.sqrt(2) +Math.sqrt(3)
with a space before the + but not after get compiled to
Math.sqrt(2)(+Math.sqrt(3));
which are not meaningful.

@vendethiel
Copy link
Collaborator

Which is expected in a whitespace-sensitive language.

@Kambis
Copy link
Author

Kambis commented Jan 28, 2013

According to which grammar rule? And why should Math.sqrt(2) +Math.sqrt(3) get compiled like that while 2 +Math.sqrt(2) gets compiled in a different way?

@vendethiel
Copy link
Collaborator

Grammar rule ? Implicit call. And 2 isn't callable so there's no possible mistake.

@Kambis
Copy link
Author

Kambis commented Jan 28, 2013

The grammar is here:
http://coffeescript.org/documentation/docs/grammar.html

@vendethiel
Copy link
Collaborator

Yes, but implicit calls are rewritten before

@Kambis
Copy link
Author

Kambis commented Jan 28, 2013

OK, thanks. So +/- are parsed as unary operator without the space.

@michaelficarra
Copy link
Collaborator

@Kambis: please read the duplicates that came before this. Also, x(+y) is far from useless.

@jashkenas
Copy link
Owner

To be more specific ... It's useful to keep the consistency for things like this:

print -100

callback -(sin(a) + cos(b))

... and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants