This is probably super-stupid, but I cannot get to work an object which contains a sequence of another object:
ColInfo* = object
in: string
out: string
TableInfo* = object
cols*: seq[ColInfo]
I can create var ti = TableInfo(), but
ti.cols.add(ColInfo("a","abc"))
gives me the compile error "Error: type mismatch: got <seq[ColInfo], ColInfo>...".
I understand I somehow have to initialise ti.cols, but
ti.cols = newSeq[ColInfo](0)
gives me theerror that "ti.cols can't be assigned to"..
Based off your error I believe the issue is that your object is immutable(declared with let). The following compiles fine.
type
ColInfo* = object
`in`: string
`out`: string
TableInfo* = object
cols*: seq[ColInfo]
var ti = TableInfo()
ti.cols.add ColInfo(`in`: "a", `out`: "b")
if you want to use a keyword like in or out as an identifier you need to quote it.
object construction syntax is different too
it's not necessary to initialize ti.cols before adding to it, but if you want to do so you've got the correct syntax:
https://play.nim-lang.org/#ix=2QsZ
type
ColInfo* = object
`in`: string
`out`: string
TableInfo* = object
cols*: seq[ColInfo]
var ti = TableInfo()
ti.cols.add(ColInfo(`in`:"a",`out`:"abc"))
echo ti #(cols: @[(in: "a", out: "abc")])
ti.cols = newSeq[ColInfo](0)
echo ti #(cols:@[])
Thanks for the correct example.
This lead me to realizing my problem was another one: ti was in my situation a function parameter... Making TableInfo a ref object fixed all my problems.
Thanks again for chiming in - and not laughing at me... :-)