I am brand new to Nim and am bumping into some issues. The following code results in SIGSEGV: Illegal storage access. (Attempt to read from nil?)
. I can't seem to figure out how to populate a sequence of sequences with values.
const
a = @[ 0, 1, 2, 3, 4, 5]
b = @[10, 11, 12, 13, 14, 15]
var
matrix: seq[seq[int]]
for i, aa in a:
for j, bb in b:
matrix[i][j] = aa+bb
Other approaches I've attempted seem to be closer...
var
matrix = newSeq[seq[int]]()
for i, aa in a:
var row = newSeq[int]()
for j, bb in b:
row[i] = aa+bb
matrix[i] = row
...but now I'm hitting out of bounds [IndexError]
...
var
matrix = newSeq[seq[int]](5)
for i, aa in a:
var row = newSeq[int](5)
for j, bb in b:
row[i] = aa+bb
matrix[i] = row
...what am I doing wrong?