i have the following:
var zmyseq = newSeqWith(6, newSeq[int](0))
zmyseq[0] = @[3,43,97,1,0]
zmyseq[1] = @[1,2,3,4,5]
zmyseq[2] = @[87,43,2,7,55]
zmyseq[3] = @[1,62,2,99,3,4,5]
zmyseq[4] = @[7,5,32,1,1]
zmyseq[5] = @[90,1,5,68,6]
echo "zmyseq[0]: " , zmyseq[0]
echo "zmyseq[1]: " , zmyseq[1]
echo "zmyseq[2]: " , zmyseq[2]
echo "zmyseq[3][2]: " , zmyseq[3][2]
echo "zmyseq[4]: " , zmyseq[4]
echo "zmyseq[5]: " , zmyseq[5]
I want to be able to keep adding and removing the number of zmyseq [infinite] on the fly since right now I am limited to what I declared (6). how do I do this?
I can not really guess what you desire. Maybe
zmyseq.add(newSeq[int]())
zmyseq[6].add(77)
zmyseq.add(@[90,1,5,68,6])
echo zmyseq[6]
echo zmyseq[7]
And removing items? Well I guess something like delete, pop, setlen should exist for sequences. Maybe read the tutorial (part 1 is really fine now), Dominiks book and sequence docs.
Maybe something like this:
import cx , sequtils
var zmyseq = newSeq[seq[int]]()
proc addseq():seq[int] =
result = createSeqInt(6,0,100)
# show it
proc showit() =
for x in 0.. <zmyseq.len:
echo "zmyseq[" & $x & "] ",zmyseq[x]
echo("Add 6 seq[int] to zmyseq")
for x in 0.. 5:
zmyseq.add(addseq())
showit()
echo("\nDelete the zmyseq[3] above")
delete(zmyseq,3,3)
showit()
# example output
#
# Add 6 seq[int] to zmyseq
# zmyseq[0] @[41, 83, 48, 57, 41, 19]
# zmyseq[1] @[1, 29, 52, 69, 13, 35]
# zmyseq[2] @[16, 99, 20, 4, 63, 95]
# zmyseq[3] @[46, 41, 29, 10, 50, 95]
# zmyseq[4] @[22, 35, 56, 75, 10, 0]
# zmyseq[5] @[39, 11, 58, 48, 43, 15]
#
# Delete the third one
# zmyseq[0] @[41, 83, 48, 57, 41, 19]
# zmyseq[1] @[1, 29, 52, 69, 13, 35]
# zmyseq[2] @[16, 99, 20, 4, 63, 95]
# zmyseq[3] @[22, 35, 56, 75, 10, 0]
# zmyseq[4] @[39, 11, 58, 48, 43, 15]
If you want to make the seq type behave like the Matrices in Matlab, change the way you are thinking. Extending the seq type when you don't intend to do it can lead to very bad performance or bugs in Matlab that are hard to find.
Maybe what you are looking for is a table
zmyseq.add(newSeq[int]())
zmyseq[6].add(77)
zmyseq.add(@[90,1,5,68,6])
it worked perfectly ! thank you