-
Notifications
You must be signed in to change notification settings - Fork 227
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
Negative index in array.remove off by one error? #1219
Comments
Similar behavior with slice: (slice [10 20 30 40 50] -1) # => ()
(slice [10 20 30 40 50] -2) # => (50) |
Check the doc here https://janet-lang.org/api/array.html#array/slice please |
Ok, it seems it is intended. But then it should be mentioned and emphasized in the documentation of every function that uses that convention, because Janet is the only language I know to use |
I'm going to throw my hat in the ring, and say that the behavior of On the other hand, I think that the behavior of - Note that index -1 is synonymous with index `(length arrtup)` to allow a full negative slice range.
+ Note that if the range is negative, it is taken as (start, end] to allow a full negative slice range. This defines the same behavior, without the need to define index -1 to be "outside" the array, which doesn't make sense for any other function. |
Now that I thought about it a bit more — I don't buy it. Slice can be used without (array/slice @[10 20 30 40 50] 1)
(array/slice @[10 20 30 40 50] -2) No need to do: (array/slice @[10 20 30 40 50] 1 -1)
(array/slice @[10 20 30 40 50] -2 -1) |
@narimiran, you do not need to, indeed. But it is like that, and I do not think it will be changed. |
Just some food for thought: you are not always writing number literals by hand as arguments of the functions :-). |
I don't see how that changes the fact that using |
There are only two challenging problems in computer science: naming, cache invalidation, and +-1 problem :-). |
@narimiran Do you think #1224 addressed this issue? If so, may be this issue can be closed. |
Yep. Closing this. Thanks @primo-ppcg! |
Is this intended? (Because definitely it isn't expected)
This
+ 1
in array.c looks suspicious:janet/src/core/array.c
Line 300 in 3a4d56a
The text was updated successfully, but these errors were encountered: