file = readFile(filename)
i : int = 0
for word in split(file, {'/'}):
sequence[i] = word
i += 1
However when I call this function inside another e.g.
assign_seq(names, "names.txt")
It says not able to assign to sequence[i].
I checked the documentation and it said to use var in the procedures parameters, however I get an illegal access error whenever I try this. How would I go about making the sequence get assigned in the way I want it to (storing the list of names separated by a '/' inside the sequence?)
The illegal access error is because you are likely not reserving memory for your sequence before calling assign_seq(). Example:
names = @[]
assign_seq(names, filename)
But then the code you show will fail with an index out of bounds error…
Arrays don't grow, but sequences can change size at runtime. You can preallocate one and add stuff to it later without having to keep track of indices or expected sizes:
var a: seq[string] = @[]
a.add("a")
a.add("b")
a.add("c")