tmget.nim 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. output: '''Can't access 6
  4. 10
  5. 11
  6. Can't access 6
  7. 10
  8. 11
  9. Can't access 6
  10. 10
  11. 11
  12. Can't access 6
  13. 10
  14. 11
  15. 0
  16. 10
  17. 11
  18. 0
  19. 10
  20. 11
  21. Can't access 6
  22. 5
  23. Can't access 6
  24. 10
  25. 11
  26. Can't access 6
  27. 10
  28. 11'''
  29. """
  30. import tables
  31. block:
  32. var x = initTable[int, int]()
  33. x[5] = 10
  34. try:
  35. echo x[6]
  36. except KeyError:
  37. echo "Can't access 6"
  38. echo x[5]
  39. x[5] += 1
  40. var c = x[5]
  41. echo c
  42. block:
  43. var x = newTable[int, int]()
  44. x[5] = 10
  45. try:
  46. echo x[6]
  47. except KeyError:
  48. echo "Can't access 6"
  49. echo x[5]
  50. x[5] += 1
  51. var c = x[5]
  52. echo c
  53. block:
  54. var x = initOrderedTable[int, int]()
  55. x[5] = 10
  56. try:
  57. echo x[6]
  58. except KeyError:
  59. echo "Can't access 6"
  60. echo x[5]
  61. x[5] += 1
  62. var c = x[5]
  63. echo c
  64. block:
  65. var x = newOrderedTable[int, int]()
  66. x[5] = 10
  67. try:
  68. echo x[6]
  69. except KeyError:
  70. echo "Can't access 6"
  71. echo x[5]
  72. x[5] += 1
  73. var c = x[5]
  74. echo c
  75. block:
  76. var x = initCountTable[int]()
  77. x[5] = 10
  78. try:
  79. echo x[6]
  80. except KeyError:
  81. echo "Can't access 6"
  82. echo x[5]
  83. x.inc 5, 1
  84. var c = x[5]
  85. echo c
  86. block:
  87. var x = newCountTable[int]()
  88. x[5] = 10
  89. try:
  90. echo x[6]
  91. except KeyError:
  92. echo "Can't access 6"
  93. echo x[5]
  94. x.inc 5, 1
  95. var c = x[5]
  96. echo c
  97. import sets
  98. block:
  99. var x = initHashSet[int]()
  100. x.incl 5
  101. try:
  102. echo x[6]
  103. except KeyError:
  104. echo "Can't access 6"
  105. echo x[5]
  106. import critbits
  107. block:
  108. var x: CritBitTree[int]
  109. x["5"] = 10
  110. try:
  111. echo x["6"]
  112. except KeyError:
  113. echo "Can't access 6"
  114. echo x["5"]
  115. x["5"] += 1
  116. var c = x["5"]
  117. echo c
  118. import strtabs
  119. block:
  120. var x = newStringTable()
  121. x["5"] = "10"
  122. try:
  123. echo x["6"]
  124. except KeyError:
  125. echo "Can't access 6"
  126. echo x["5"]
  127. x["5"][1] = '1'
  128. var c = x["5"]
  129. echo c