tmitems.nim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. discard """
  2. output: '''@[11, 12, 13]
  3. @[11, 12, 13]
  4. @[1, 3, 5]
  5. @[1, 3, 5]
  6. gppcbs
  7. gppcbs
  8. fpqeew
  9. fpqeew
  10. [11, 12, 13]
  11. [11, 12, 13]
  12. [11, 12, 13]
  13. [11, 12, 13]
  14. 11 12 13
  15. [11,12,13]
  16. <Students>
  17. <Student Name="Aprilfoo" />
  18. <Student Name="bar" />
  19. </Students>'''
  20. """
  21. block:
  22. var xs = @[1,2,3]
  23. for x in xs.mitems:
  24. x += 10
  25. echo xs
  26. block:
  27. var xs = [1,2,3]
  28. for x in xs.mitems:
  29. x += 10
  30. echo(@xs)
  31. block:
  32. var xs = @[1,2,3]
  33. for i, x in xs.mpairs:
  34. x += i
  35. echo xs
  36. block:
  37. var xs = [1,2,3]
  38. for i, x in xs.mpairs:
  39. x += i
  40. echo(@xs)
  41. block:
  42. var x = "foobar"
  43. for c in x.mitems:
  44. inc c
  45. echo x
  46. block:
  47. var x = "foobar"
  48. var y = cast[cstring](addr x[0])
  49. for c in y.mitems:
  50. inc c
  51. echo x
  52. block:
  53. var x = "foobar"
  54. for i, c in x.mpairs:
  55. inc c, i
  56. echo x
  57. block:
  58. var x = "foobar"
  59. var y = cast[cstring](addr x[0])
  60. for i, c in y.mpairs:
  61. inc c, i
  62. echo x
  63. import lists
  64. block:
  65. var sl = initSinglyLinkedList[int]()
  66. sl.prepend(3)
  67. sl.prepend(2)
  68. sl.prepend(1)
  69. for x in sl.mitems:
  70. x += 10
  71. echo sl
  72. block:
  73. var sl = initDoublyLinkedList[int]()
  74. sl.append(1)
  75. sl.append(2)
  76. sl.append(3)
  77. for x in sl.mitems:
  78. x += 10
  79. echo sl
  80. block:
  81. var sl = initDoublyLinkedRing[int]()
  82. sl.append(1)
  83. sl.append(2)
  84. sl.append(3)
  85. for x in sl.mitems:
  86. x += 10
  87. echo sl
  88. import deques
  89. block:
  90. var q = initDeque[int]()
  91. q.addLast(1)
  92. q.addLast(2)
  93. q.addLast(3)
  94. for x in q.mitems:
  95. x += 10
  96. echo q
  97. import json
  98. block:
  99. var j = parseJson """{"key1": 1, "key2": 2, "key3": 3}"""
  100. for key,val in j.pairs:
  101. val.num += 10
  102. echo j["key1"], " ", j["key2"], " ", j["key3"]
  103. block:
  104. var j = parseJson """[1, 2, 3]"""
  105. for x in j.mitems:
  106. x.num += 10
  107. echo j
  108. import xmltree, xmlparser, streams, strtabs
  109. block:
  110. var d = parseXml(newStringStream """<Students>
  111. <Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
  112. <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
  113. </Students>""")
  114. for x in d.mitems:
  115. x = <>Student(Name=x.attrs["Name"] & "foo")
  116. d[1].attrs["Name"] = "bar"
  117. echo d