Associative array/Creation: Difference between revisions
Content added Content deleted
m (BaCon, BASIC256, and BBC BASIC moved to the BASIC section.) |
No edit summary |
||
Line 2,925: | Line 2,925: | ||
<code>define-hash-table-test</code> can create other key comparison types. |
<code>define-hash-table-test</code> can create other key comparison types. |
||
=={{header|EMal}}== |
|||
<syntaxhighlight lang="emal"> |
|||
Map empty = Map(int, text) # creates an empty map |
|||
writeLine(empty) |
|||
var longFruit = Map(int, text).of(1, "banana") # creates a map with the pair 1 => "banana" |
|||
longFruit[2] = "melon" # associates a key of 2 with "melong" |
|||
longFruit.insert(3, "avocado") |
|||
writeLine(longFruit) # prints the map |
|||
var shortFruit = int%text[4 => "kiwi", 5 => "apple"] # map creation using arrow notation |
|||
writeLine(shortFruit[5]) # retrieves the value with a key of 5 and prints it out |
|||
writeLine(shortFruit.length) # prints the number of entries |
|||
writeLine(shortFruit) # prints the map |
|||
writeLine(text%text["Italy" => "Rome", "France" => "Paris", "Germany" => "Berlin", "Spain" => "Madrid"]) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
[] |
|||
[1:banana,2:melon,3:avocado] |
|||
apple |
|||
2 |
|||
[4:kiwi,5:apple] |
|||
[Italy:Rome,France:Paris,Germany:Berlin,Spain:Madrid] |
|||
</pre> |
|||
=={{header|Erlang}}== |
=={{header|Erlang}}== |