tmget.nim 1.7 KB

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