What is the difference between a collection of associations and a dictionary in Smalltalk?

| dict |
dict := #{'foo'->'brown'. 'bar'->'yellow'.
          'qix'->'white'. 'baz'->'red'. 'flub'->'green'} asDictionary.
dict at: 'qix'

If I do PrintIt, I get white. If I remove "asDictionary", I still get "white". What does the dictionary give me that a collection of associations does not?

+4
source share
2 answers

An expression like #{exp1 . sxp2 . exp3}, specific and creates a HashedCollection, which is a special type of dictionary where the keys are strings (maybe in Javascript you use such things so much).

In other small tones there is no such expression. Instead of array expressions that look like this: {exp1 . sxp2 . exp3}(no leading #) were entered inas well as available in ( Squeak) Amber. Array, #at:. , dict at: 2 'bar'->'yellow', .

#asDictionary - , , , . , , , :

dict := {
    'foo' -> 'brown'  .
        1 -> 'yellow' .
    3 @ 4 -> 'white'  .
   #(1 2) -> 'red' } asDictionary
+7

A Dictionary Association s. , , Smalltalk . ( Association - , ).

, ,, , .

A Dictionary :
 removeKey: aKey . aKey
 includesKey: aKey .
 includes: aValue .
 at:put: .

anAssociation := Association key:value:   .
aDictionary add:    

.

anAssociation := Association key:   'Hello' 
                             value: 'A greeting people often use' .
aDictionary add: anAssociation .

, at:put , , .

, . , .

anAssociation := Association key: 'keyOfElement' value: 'valueOfElement'  

, ,

anAssociation := 'keyOfElement' -> 'valueOfElement'  

Symbol s, Class IdentityDictionary

+2

All Articles