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

Content deleted Content added
Yobot (talk | contribs)
m WP:CHECKWIKI error fixes + general fixes using AWB (7521)
added scala
Line 1,031:
array_map (Void_Type, &vmessage, "%s %s", keys[i], vals[i]);
</source>
 
===Scala===
[[Scala (programming language)|Scala]] provides a immutable Map class as part of the scala.collection framework:
 
<source lang="scala">
val phonebook = Map("Sally Smart" -> "555-9999",
"John Doe" -> "555-1212",
"J. Random Hacker" -> "553-1337")
</source>
 
Scala's type inference will work out that this is a <code>Map[String, String]</code>. To access the array:
 
<source lang="scala">
phonebook.get("Sally Smart")
</source>
 
This returns an Option type, Scala's equivalent of a [[Monad_(functional_programming)#Maybe_monad|the Maybe monad]] in Haskell.
 
===Smalltalk===