Replies: 13 comments 1 reply
-
I agree with having the two operators, but propose the different syntax below. for i in 1..5 {
println(i) // 1,2,3,4,5
}
for i in 1<..5 {
println(i) // 2,3,4,5
}
for i in 1..<5 {
println(i) // 1,2,3,4
}
for i in 1<..<5 {
println(i) // 2,3,4
} The advantage of this syntax is that you don't need to "count" how many dots are there (which I think is error-prone). |
Beta Was this translation helpful? Give feedback.
-
And similarly maybe we could consider this... arr := [0,1,2,3,4,5]
println(arr[1..4]) // [1,2,3,4]
println(arr[1<..4]) // [2,3,4]
println(arr[1..<4]) // [1,2,3]
println(arr[1<..<4]) // [2,3] |
Beta Was this translation helpful? Give feedback.
-
We already have this for i in 1..5 {
println(i)
} Output 1
2
3
4 |
Beta Was this translation helpful? Give feedback.
-
@Delta456 Yes. Since V has a philosophy of "unique way", maybe keeping the current syntax (there's only one range operation - a..b means [a,b) ) is not bad. |
Beta Was this translation helpful? Give feedback.
-
I probably missed the discussion around the current range operator, but I find a mix of inclusive and exclusive rather unintuitive. I would have expected that a loop over 1 to 3 does include 3: for i in 1..3 {
println(i)
} Output:
I would prefer to have the default as a intuitive as possible. And advanced syntax is usually not needed if math operators will do the trick. In case the code below is working, I guess no additional sytnax is required.
|
Beta Was this translation helpful? Give feedback.
-
A '1..5' range not including '5' although completely counterintuitive at first sight, makes sense about zero base arrays:
MAYBE a new language derived from V (just the one base arrays part) could work fine. |
Beta Was this translation helpful? Give feedback.
-
I have no proposal about this. |
Beta Was this translation helpful? Give feedback.
-
I have no proposal about this.
A just want to point how counterintuitive this range design is
Yes: Take a look at "wren" http://wren.io/values.html#ranges - i think
they do it right.
|
Beta Was this translation helpful? Give feedback.
-
Don't get me wrong.
As the decision is not for me, I try to understand what are the reasons of Alex Medvednikov. I think he wants a language where C programmers feel at home. That is why I said I had no proposal, because I fear that some features that I love have no match with strategy/culture/market of V. |
Beta Was this translation helpful? Give feedback.
-
We have I don't find Anyway, it would be nice to have Please don't lua the language. Base 1 arrays are annoying to work with. I have experience with base 1 arrays and image/matrix processing, what a nightmare. |
Beta Was this translation helpful? Give feedback.
-
These topics have been discussed many times in the past, and I suppose will keep coming up from time to time. This is why V needs ADRs. Arrays in V will always start at 0. 98+% of programming languages start arrays at 0. V is similar to Go, which starts arrays at 0, and V outputs C by default, which starts arrays at 0. V can also output JavaScript (where arrays start at 0), Python arrays start at 0, etc., etc.
|
Beta Was this translation helpful? Give feedback.
-
So inclusive end is enough:
|
Beta Was this translation helpful? Give feedback.
-
For now a..b == [a, b) and it's a bit confusing because left-side inclusive and right-side exclusive but both looks the same. a..b == [a, b] // right-side inclusive There's no need for this but it would be nice to have this as a syntactic sugar. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions