home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RB3641.ZIP / EX1 / COLLECT1.ST < prev    next >
Text File  |  1990-05-08  |  2KB  |  109 lines

  1. "In the following exercises all expressions
  2.  should be evaluated with ShowIt after
  3.  selecting the text to be executed"
  4.  
  5.  
  6. "A new instance of Dictionary is created
  7.  by evaluating the following expression
  8.  with DoIt or ShowIt"
  9.  
  10.  
  11. Dictionary new.                      
  12.  
  13.  
  14. "If an instance variable is to be assigned
  15.  to this new object, it can be done by
  16.  evaluating the following expression:"
  17.  
  18.  
  19. | myDict |
  20. myDict := Dictionary new.
  21.  
  22.  
  23.  
  24. "To insert key/value pairs we can use
  25.  'at: put: method"
  26.  
  27.  
  28.  
  29. | myDict |
  30. myDict := Dictionary new.
  31. myDict at: 'James Bond' put: 007.
  32. myDict at: 'Mr Devil' put: 666.
  33. myDict at: 'Maggie' put: 10.
  34. myDict at: 'Myself' put: 552936.
  35.                                                                            
  36.  
  37.  
  38. "If you want to query the values inserted,
  39.  'at:' method can be used as follows:
  40.  ( evaluate with ShowIt )"
  41.  
  42.  
  43.  
  44. | myDict |
  45. myDict := Dictionary new.
  46. myDict at: 'James Bond' put: 007.
  47. myDict at: 'Mr Devil' put: 666.
  48. myDict at: 'Maggie' put: 10.
  49. myDict at: 'Myself' put: 552936.
  50. "now let's query something"
  51. myDict at: 'Maggie'.                        
  52.  
  53.  
  54. "To query the value of the key 'keyAtValue'-
  55.  method can be used:"
  56.  
  57. | myDict |
  58. myDict := Dictionary new.
  59. myDict at: 'James Bond' put: 007.
  60. myDict at: 'Mr Devil' put: 666.
  61. myDict at: 'Maggie' put: 10.
  62. myDict at: 'Myself' put: 552936.
  63. "now let's query something"
  64. myDict keyAtValue: 007.     
  65.  
  66. "Now let's remove some value/key pair
  67.  using 'removeKey:' method "
  68.  
  69.  
  70. | myDict |
  71. myDict := Dictionary new.
  72. myDict at: 'James Bond' put: 007.
  73. myDict at: 'Mr Devil' put: 666.
  74. myDict at: 'Maggie' put: 10.
  75. myDict at: 'Myself' put: 552936.
  76. myDict removeKey: 'James Bond'.
  77. myDict keyAtValue: 007.                                              
  78.  
  79.  
  80. "To change a value associated with
  81.  a key simply overwrite the old one"
  82.  
  83.  
  84. | myDict |
  85. myDict := Dictionary new.
  86. myDict at: 'James Bond' put: 007.
  87. myDict at: 'Mr Devil' put: 666.
  88. myDict at: 'Maggie' put: 10.
  89. myDict at: 'Myself' put: 552936.
  90. "now let's replace something"
  91. myDict at: 'Maggie' put: 11.
  92. myDict at: 'Maggie'.
  93.  
  94.  
  95.  
  96. " Activate the Smalltalk inspector to display
  97. the contents of the collection (Evaluate    
  98. with DoIt)."
  99.  
  100. | myDict |
  101. myDict := Dictionary new.
  102. myDict at: 'James Bond' put: 007.
  103. myDict at: 'Mr Devil' put: 666.
  104. myDict at: 'Maggie' put: 10.
  105. myDict at: 'Myself' put: 552936.     
  106. myDict inspect.
  107.  
  108.  
  109.