jashkenas/coffee-script — pull request #1955 by clutchski (2011-12-21 00:43:55+00:00)
Title: Allowing both end-points of slices to be implicit.

Hey there,

This is a small patch to the grammar to allow both end-points of a slice to be omitted and thus default to the end points of the array. Here's an example:

coffee> x = [1, 2, 3]
[ 1, 2, 3 ]
coffee> x[..]
[ 1, 2, 3 ]

This patch gives three nice things:

- Consistency with the existing slice operations, since they allow either end-point to be omitted, but not both (throws an "Unexpected Index End error")
- A nice little idiom for copying arrays.
- Consistency with other languages slice implementations, like Python.

If you think it belongs, I'd be more than happy to add an example to the docs. If not, thanks anyway.

Matt

PS - I checked in the lib/*.js files and I'm not sure that makes sense, because parser.js had a ton of changes and I don't think it had been checked in some time and had many unrelated changes. If you want to accept this patch and that's wrong, let me know and I'll clean it up.