-
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
Remove Ranges, introduce "from x to y" #746
Comments
By no means criticising, but here are my thoughts:
List of 1 to 5
So does
Agreed, but
How does
I hate remembering which one is which. More dots -- inclusive, right? Wrong. |
The loop range supports
By removing them.
Exactly. |
I kind of like |
Maybe it could stay in the form of The fact that no splicing is used in the compiler itself (albeit the extensive use of |
I implemented a branch once (long time ago, dark ages) that supported both negative indices and Back to the point, let's take out splices then and have a syntax for |
Well of course it's a must-have feature. But since JS's
|
If we do pursue this direction, I don't think that
... should be legit. |
|
It'd be great to lose the |
What about having a |
This is a great idea.
I'd prefer it to be exclusive by default, to be consistent with JS's |
To me, |
http://github.com/satyr/coffee-script/compare/master...to |
I'd like to merge this soon, and there's one more issue discussed in I'm not a big fan of our
Sound reasonable? Anyone using the insta-arrays? |
+1 for removing I would still prefer |
@akva: I would argue that the idiom of iterating from @jashkenas: +1 for losing the |
sethaurus: just to have one less piece of rarely-used special syntax. |
In the absence of range literals, the
|
@sethaurus I was actually going to propose this syntax too. I like it better. The only objection is that it introduces a new keyword |
This may actually solve the keyword problem. |
That sounds like the best of both worlds. |
@satyr Sounds good. Then you can write |
Nice! Glad we won't have to reserve |
http://github.com/satyr/coffee-script/compare/master...fromto
|
I don't want to lose ranges or slicing, and I think satyr's branch above does a fair job of showing why. Reading the code, I prefer the previous version, even though 1 to 5 is much nicer than [1..5]. The .slice method is exclusive and reads poorly, and ranges are too handy a shorthand to throw away completely. I use them all the time in my tests. I have no idea if the following is parsable, but what about something like this?
|
Well, the |
@hiddenbek: glad I am not the only one not too fond of the new syntax. Kind of sold on it, but not there just yet.
Besides ranges are cool:
|
@Tesco: Right,
@StanAngeloff: It definitely feels like one step forward, two steps back. I prefer reading the new version, but I quickly scan my code more often than I actually read it, and the new version turns into a jumble of words while scanning. The old way makes it easy to identify the important bits at a glance. That said, if we could keep slices and ranges, I'd still call it a win. |
Let's stop imitating Ruby. We can do better, right? ;) |
I don't think the exclusivity of |
I like the |
satyr -- mind rebasing your fix against the current master? There's a pretty large set of merge conflicts between the two branches at the moment, and I don't feel expert enough in the patch to try and resolve them. |
Done rebasing over master, without slice/splice/range and the scope magic. Considering #781, should we change
to
or even
? |
The new |
Two cents regarding iterating downwards... Instead of: |
Was this syntax reverted? I'm using 1.2.0, which should be after the merge, and I'm getting a parse error: coffee> i for i in [1..10]
[ 1,
2,
3,
4,
5,
6,
7,
8,
9,
10 ]
coffee> i for i from 1 to 10
Error: In repl, Parse error on line 1: Unexpected 'CALL_START'
at Object.parseError (/usr/lib/node_modules/coffee-script/lib/coffee-script/parser.js:470:11)
at Object.parse (/usr/lib/node_modules/coffee-script/lib/coffee-script/parser.js:546:22)
at /usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:40:22
at Object.eval (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:123:10)
at Interface.<anonymous> (/usr/lib/node_modules/coffee-script/lib/coffee-script/repl.js:51:34)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream.<anonymous> (readline.js:82:12)
at ReadStream.emit (events.js:88:20) |
Yep. |
tl;dr
Introduce infix
to
(with optionalby
) and replace current ranges with it.intro
The pseudo ranges may look nifty in the first glance, but I think
they've become the bad parts in CoffeeScript.
proposed syntax
instead of
why current ranges are bad
Because they
(i for i in [.0 .. .2] by .1)
[(0)...(2)]
.x = 1; y = 5; [x..y]
to
-by
would have a fixed step and thus generate better code..slice
)'012345'[-3..-1]
a = [0..5]; a[1..-2] = [42]
[x...,y]
edit: removed cup links that no longer work.
The text was updated successfully, but these errors were encountered: