-
Notifications
You must be signed in to change notification settings - Fork 13
Negative indices #5
Comments
This is just to propose the solution of array-last. The idea is to open the discussion about values such as |
So to clarify - if the committee decides that |
I am very strongly of the opinion that specializing this to just the literal last element would be a terrible mistake and not worth the effort of speccing and implementing it. Anyone with experience in langs that allow negative indexes, like Python, can tell you that while -1 is the most commonly used one, larger values aren't uncommon either. In other words, imo the discussion should start from the assumption that we'll be allowing negative indexes, and just shut off any options that wouldn't allow that. (This removes |
Closing this. The Readme has been updated to reflect the current state of this proposal which features |
Please reopen - the current state of the README explicitly disagrees with this issue, so it's valuable to capture this dissent as the proposal is reviewed. |
There's also the possibility of having |
This feels premature so long as a more generalized proposal, such as arr[-N] is an option. Should the generalized options fail, something like this makes a lot more sense. Pursuing them both simultaneously I fear undercuts the arguments for either. Perhaps the committee has a mechanism for reconciling these kinds of overlapping proposals though. |
If you really want negative indices now, check out https://github.com/sindresorhus/negative-array; I like the idea and would consider using it in future projects. |
I’d love to have I remember there were arguments against those methods, but forgot what they were. |
With regards to this proposal: If we are convinced that negative indexing is far, far on the horizon, then I support anything along the lines of While I really vastly prefer and would love to discuss negative indexing and argue in favor of ary[-N], despite the need for a feature flag, I believe that the scope of this discussion needs to be limited to this proposal with respect to negative indexing. As such, I do agree with @uniqname - shooting for this feature could reduce demand and drive for negative indexing. However, the ability to quickly and explicitly access 'last' is valuable, even with negative indexing available. I think If negative indexing were here today, I'd lean against adding this feature due to the very minor value it adds in a world with negative indexing already available. However, negative indexing is unlikely to be added all that soon, simply because breaking things or adding a feature flag is contentious, and modifying the most obvious solution simply to avoid breaking things or adding a feature flag is also contentious. |
I'd like to chime in with support for
|
It seems strange to me to just spec out
array[:-1]
orarray[-1]
and not allow other negative indices. Why not proposearray[:-N]
?The text was updated successfully, but these errors were encountered: