@MaineTim: Yup, new to Nim...

In the following, I've shortened your code just to show the essentials: 
    
    
    type
      TSeg = object
        sub: seq[int]
    
    var seg = TSeg(sub: @[])
    var segments = newSeq[TSeg]()
    
    for i in 0 .. 2: segments.add seg
    
    segments.echo
    
    segments[2].sub.add(7)
    segments.add(TSeg(sub: @[42]))
    
    segments.echo
    
    
    Run

No need to create the seq's using capacities (unless you are optimizing), 
creating all the elements from your uninitialized model of segment doesn't 
actually create any sub sequences as the default values are all zeros, 
including the deductions sub field, so you can't assign or add to it until it 
has been created with some sort of a new. In my example code, I initialized the 
model seg including initializing its seq contents with seq literal initializer 
as in @[] but you could use any sort of newSeq or newSeqOfCap, then either 
assign to the existing elements or add to the elements as you wish as I have 
done here.

Reply via email to