the above is ok.
Since what it does is to create an array and convert that array to a seq, I can infer that what you put there should be fine.
try something like:
proc test(arr: var seq[int]) =
for i in arr.low..arr.high:
arr[i].inc
The reason you can't mutate inc(a) is because when you write for a in arr in this case the compiler replaces that with for a in system.items(arr). And if we look at the documentation of this iterator we can see it returns a non mutable copy of each item in the sequence. Fortunately you can also use the see source link and copy it into your own mutable version like this:
iterator mitems*[T](a: var seq[T]): var T {.inline.} =
var i = 0
let L = len(a)
while i < L:
yield a[i]
inc(i)
assert(len(a) == L, "seq modified while iterating over it")
proc test(arr: var seq[int]) =
for a in arr.mitems:
inc(a)
when isMainModule:
var data = @[1, 2, 3]
echo data.repr # --> [1, 2, 3]
data.test
echo data.repr # --> [2, 3, 4]
If you feel brave enough you can submit this alternative version to the developers for inclusion in a future version.