#void proc modifySeq(mySeq: var seq[int]) = mySeq[9] = 999 # string simple works proc crStr(): string = "doing c" # does not work in this way proc crePopulatSeqStr(parSz: int): seq[string] = #started with a builtin type result = newSeq[string](parSz) for i in 0..parSz: result.add("do f-" & $i) echo crePopulatSeqStr(10)[0]
You are creating a seq of length parSz (filled with nil) and then appending to it.
What you want to do is start from an empty seq and append, or create the seq of the given length and then assign to the existing slots (instead of appending).
That is, this will work
proc crePopulatSeqStr(parSz: int): seq[string] = #started with a builtin type
result = @[]
for i in 0.. < parSz:
result.add("do f-" & $i)
and this will as well
proc crePopulatSeqStr(parSz: int): seq[string] = #started with a builtin type
result = newSeq[string](parSz)
for i in 0.. < parSz:
result[i] = "do f-" & $i