-
Notifications
You must be signed in to change notification settings - Fork 2k
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
a +"b" compiles to a(+"b") #1036
Comments
This behavior definitely feels weird coming from most languages (in Scala, for instance, I believe the preferred String concatenation style is
Again, that's just JavaScript—CoffeeScript simply keeps the behavior the same. So given that Of course, you're probably aware that the preferred string concatenation style in CoffeeScript, as in Ruby, is
|
Nope? |
Hi Trevor, thanks for the response. I'm aware of the unary + operator, but in plain JS it's not space sensitive.
Though a workaround in CoffeeScript is to write it thusly:
Or
As for the string interpolation, I definitely prefer to use that where possible, but I primarily use CoffeeScript from filters within my Rails application so the Ruby interpolation overrides it. |
@satyr Sorry, that last part was posted by mistake. Corrected. Bummer about the filters, STRd6. That didn't occur to me when we were debating the string interpolation syntax. Maybe Of course, another syntactic option would be for you to write a function:
|
I posted a new similar report but I've noticed that similar one is already reported. I am using coffeescript for a large javascript project since August. We ended up using 0.9.4 for some time. Today I did some verifications if we can safely upgrade do 1.0 and I this is the first issue that I discovered (and it was compiling properly under 0.9.4): I am not sure if consider this as a bug (there are reasons when space character is treated as start of function call) but IMO coffeescript compiler should detect expressions as an exception and it was doing so in 0.9.4. |
|
@satyr. I am not sure if I understood your point (having great respect for your contribution to coffeescript) but my point is that: but in 1.0 coffeescript: edit: I got it now - I keep forgetting about p as a puts shortcut. |
Unlike JS, Ruby has separate namespaces for methods and variables.
|
I'm afraid that the current behavior is the correct fix. With
In CoffeeScript, the above must parse as |
Since folks are still talking about this, here's a concrete example of why this is useful:
It wouldn't feel very CoffeeScript-y to require parentheses there, now would it? |
Except that the |
Well, OK, good point:
|
Is this mentioned in the documentation yet? I think Coffee's behaviour is perfectly sensible here, but very surprising if one's not used to it. Unlike the block structure via indentation thing, which even after years of Python programming I'm still not too happy about, this is actually a use of significant white space that I can get behind. In fact, |
Added to the FAQ under Grammar. |
It may be my expectations that are to blame, but I would expect this to compile to:
or something equivalent. The prefix + operator and function call are surprising.
The text was updated successfully, but these errors were encountered: