Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
Scala: copy editing
Smalltalk: copy editing
Line 1,716:
This returns an <code>Option</code> type, Scala's equivalent of the [[Monad (functional programming)#The Maybe monad|Maybe monad]] in Haskell.
 
=== [[Smalltalk]] ===
In [[Smalltalk]] a dictionary<code>Dictionary</code> is used:
 
<syntaxhighlight lang=Smalltalk>
Line 1,726:
</syntaxhighlight>
 
To access an entry the message <code>#at:</code> is sent to the dictionary object.:
 
<syntaxhighlight lang=Smalltalk>
Line 1,732:
</syntaxhighlight>
 
Which gives:
 
<syntaxhighlight lang=Text>
'555-9999'
</syntaxhighlight>
 
DictionaryA dictionary hashes/, or compares, based on equality and holdsmarks both key and value as
[[Garbage collection (computer science)#Strong and weak references|strong references]] to both key and value. Variants exist in which hash/compare on identity (IdentityDictionary) or keep [[Garbage collection (computer science)#Strong and weak references|weak references]] (WeakKeyDictionary / WeakValueDictionary).
Because every object implements #hash, any object can be used as key (and of course also as value).