File: tseqcon.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (51 lines) | stat: -rw-r--r-- 939 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
discard """
  file: "tseqcon.nim"
  output: "Hithere, what\'s your name?Hathere, what\'s your name?"
"""
# Test the add proc for sequences and strings

const
  nestedFixed = true

type
  TRec {.final.} = object
    x, y: int
    s: string
    seq: seq[string]
  TRecSeq = seq[TRec]

proc test() =
  var s, b: seq[string]
  s = @[]
  add(s, "Hi")
  add(s, "there, ")
  add(s, "what's your name?")

  b = s # deep copying here!
  b[0][1] = 'a'

  for i in 0 .. len(s)-1:
    write(stdout, s[i])
  for i in 0 .. len(b)-1:
    write(stdout, b[i])


when nestedFixed:
  proc nested() =
    var
      s: seq[seq[string]]
    for i in 0..10_000: # test if the garbage collector
      # now works with sequences
      s = @[
        @["A", "B", "C", "D"],
        @["E", "F", "G", "H"],
        @["I", "J", "K", "L"],
        @["M", "N", "O", "P"]]

test()
when nestedFixed:
  nested()

#OUT Hithere, what's your name?Hathere, what's your name?