for _ in [1..10] doesn't compile
per accident, range was not working, i used for _ in [1..10] { instead of for _ in 1..10 {
i was said to create an issue because i had found a bug so i did now.
There is no integer range syntax AFAIK. Instead, use C for syntax. We could have a count function returning an iterator though (if for supported iterators):
for i in count(1, 10) {
I'll post more on iterators soon.
plese look here: https://vlang.io/compare and then to the V example
V will have min..max soon. I actually thought it was live, but it's temporarily on a branch.
min .. (min+length-1) -- yuck!
I don't care about 0-based or 1-based indexing. But I hate not knowing where a range ends. The simple solution, overlooked in most languages, is to use the length for the second argument.
With .. that would throw people off. But maybe a different syntax could be used. Ideas:
for i in min @ lengthfor i in min -> lengthfor i in min : lengthfor i in min ..@ length
V will have min..max soon
I think slice syntax for arrays and strings should be the same then, so arr[min .. max], and the max index value is excluded. Built-in range syntax would be useful in match cases, but there they need to include max so three dots could be used:
c := get_char()
n := match c {
`0` ... `9` -> c - '0'
`a` ... `f` -> c - 'a' + 10
else {println('$(c.str()) is not a hex digit'); continue}
}
min .. (min+length-1)
That would be min .. length - 1 to exclude the last valid index.
Fixed.
[1..10] == [[1,2,3,4,5,6,7,8,9]] by the way.
I think slice syntax for arrays and strings should be the same then
Agreed, I'll have to pick one.
Actually, if 1..4 means an array literal, then slice syntax should be different. arr[1..4] would look like it meant arr[[1,2,3]]. So maybe arr[start:end] should be the syntax, like Go (where start and end are both optional).