-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
more powerful range operations #4933
Comments
I like A, but... if a[1] is the 2nd element in the array, but a[-1] is the last, it almost seems like an "off-by-1" problem. I think B is a bit confusing, and could be error-prone. At the least, it will take a while to get the syntax correct. C... it just saves 2 characters. I don't see the need. D same as B. Just my opinions. |
Among the four proposals, I would rather see Proposal A be implemented. |
Negative indexing gets suggested a lot. It will never be implemented due to being too bug prone. An unexpected value can mess up the entire program. |
|
I think one possible way to prevent error-prone negative index is using another char indicating negative (better say, indicating 'from back to front'), e.g. And I think it's better to explain my proposals with some real cases. CASE a. result_var := this_is_a_var[this_is_a_var.len-10..][this_is_a_var.len-10..] // now
result_var := this_is_a_var[#10.., #10..] // proposal CASE b. // now
result_var := generate_array_with_zeros(this_is_another_var.len[0], this_is_another_var.len[1], (this_is_another_var.len[2] + 1) / 2, (this_is_another_var.len[3] + 1) / 2)
for i in 0..result_var.len[2] {
for j in 0..result_var.len[3] {
result_var[..][..][i][j] = this_is_another_var[..][..][2*i][2*j]
}
}
reverse_array_on_dim(result_var, 2, 3)
result_var := this_is_another_var[.., .., ..#2.., ..#2..] // proposal
result_var := this_is_another_var[ , , ..#2.., ..#2..] // proposal - even this BTW, start_pos-interval-end_pos (or start_pos-end_pos-interval) is common in scientific computing languages, e.g. # Python
arr[1:10:2] # arr[1], arr[3], arr[5], arr[7], arr[9] % MATLAB
for i = 1:2:100
disp(i) % print 1,3,5,...,99
end |
That makes more sense in context. |
I only like proposal A |
I like ruby ranges, very few cases: |
For those who want a fine-grained range generation, theres https://github.com/Delta456/range |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I propose V provides more powerful range operations. More specific,
Also, Q&A (some personal views):
a. Now a..b means [a, b) instead of [a, b], is this nice?
I think yes, [a, b) is sometimes more elegant - 0..a.len better than 0..a.len-1.
b. About proposal B, why not start_pos..end_pos..interval?
This comes from V's len=2 range op (
..
).Think about reverse operation as an example, if so, then we have to write
In contrast,
start_pos..interval..end_pos
doesn't have this issue - omitting interval means interval=1, so there's no point in writinga[....-1]
. Just writea[..-1]
instead.c. Why proposal C? Just for less keyboard pressing?
No. V has len=2 range op (
..
) rather than len=1 (e.g.:
) so omitting unnecessary ones helps keep elegant. Think about an dim=10 array.The text was updated successfully, but these errors were encountered: