Content deleted Content added
+link |
Kwamikagami (talk | contribs) m fmt using AWB |
||
Line 194:
=== D ===
[[D programming language|D]] offers direct support for associative arrays
in the core language
<source lang="d">
Line 299:
<pre>
mapping = NEWOBJECT("Collection")
mapping.Add("Daffodils", "flower2") && Add(object, key)
index = mapping.GetKey("flower2") && returns the index value 1
object = mapping("flower2") && returns "Daffodils" (retrieve by key)
Line 545:
["Sally Smart"] = "555-9999",
["John Doe"] = "555-1212",
["J. Random Hacker"] = "553-1337",
}
aTable = {
-- Table as value
subTable = { 5, 7.5, k = true },
-- Function as value
['John Doe'] = function (age) if age < 18 then return "Young" else return "Old!" end end,
Line 716:
</source>
Accessing a hash element uses the syntax <code>$hash_name{$key}</code>
The list of keys and values can be extracted using the built-in functions <code>keys</code> and <code>values</code>, respectively. So, for example, to print all the keys of a hash:
|