-
Notifications
You must be signed in to change notification settings - Fork 2k
add support for unbounded array slicing/splicing #621
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Oh, I completely forgot to search for this before posting. Sorry. |
IMO, this sugar should be removed if it can't support this idea and/or negative indices. |
Yes, that is actually why I had the idea. Check this out:
and it still doesn't even compile to |
Thanks for digging up those earlier tickets, StanAngeloff. @satyr: I'm not sure what you're saying. @michaelficarra: As I recall, the main objection Jeremy had to making All of which we can debate endlessly, but let me just point out a couple of current inconsistencies that need to be resolved somehow: First, Second, a lot of folks (myself included) have discovered this frustrating pattern:
Sure, it makes perfect sense when you peek under the hood, but only then. Of course, there's no way to solve this while still piping ranges directly into Suggestions? |
There was some talking about introducing a new syntax to deal with all the above limitations. The It's just one of those impossible tickets... I for one have tried three different patches and none of them came close to solving all of the issues (though pretty close). |
I just implemented this in Kaffeine. I figured that A[x...] should just be the same as A[x..](that's what it looks like intuitively). |
Ah, I'm afraid this was one of Jeremy's stronger arguments, weepy: To me, it makes more sense for |
yeh well u have to make a call either way. i think it's better to have the feature than worry about 'newbies' not understanding. After all it's only really JS wizards that will be using this stuff. |
So, what's the proposal then? Would folks rather have slice literals removed from CoffeeScript, than have to specify the end of the slice? michaelficarra: what do you think after reading though those old tickets? |
Only accidentally so. It's a live code piece which I think is stemmed from the fact that Splicing is messy as well:
|
Here's my proposal: Make the range/slice syntax compile to wrapper functions, when necessary, that give us all of the nice functionality we want, including:
I still think the trailing syntax (being able to leave out Performance geeks can use Edit: This is pretty far afield from the original topic, so I'm going to make a separate issue for this proposal. |
@jashkenas: After sleeping on it and consulting a few programmer friends, I believe it is proper to allow unbounded slices/splices. This is mainly based on the use case I provided above.
|
Alrighty. I worked out how to get unbounded slices into the grammar ... by making splats only possible in the context of argument and parameter lists, where they belong. Here's the patch: http://github.com/jashkenas/coffee-script/commit/4ddd65a4c4df5baa4911bf095246a7829e9acca6 Here's the test case from the patch:
Take a look at this one if you have a minute, because I want to make sure that we have all of the off-by-one errors correct here. |
Glad to know this got in! |
THANKING YOU ! |
Yes, I am very pleased with this patch as well. Thanks for adding it! |
Recall the array slicing operator: [x..y]. This operator extracts slices of arrays, and compiles like so:
I've collected some related examples that are not part of the language, but I believe should be, and what they should compile to.
and if we want to get a little saucy:
I'm not so sure about those last two yet, but they are ideas. Can I hear some thoughts on this? Also, remember that these slices can be assigned to, so this should be discussed as well.
The text was updated successfully, but these errors were encountered: