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

Content deleted Content added
Lua: copy editing
Mathematica and Wolfram Language: copy editing and linking
Line 1,027:
</syntaxhighlight>
 
=== [[Mathematica]] and [[Wolfram Language]] ===
 
[[Mathematica]] usesand [[Wolfram Language]] use the Association expression to represent associative arrays.<ref>{{cite web|url=https://reference.wolfram.com/language/ref/Association.html|title=Association (<-...->)—Wolfram Language Documentation|website=reference.wolfram.com}}</ref> expression to represent associative arrays.
 
Mathematica uses the Association<ref>{{cite web|url=https://reference.wolfram.com/language/ref/Association.html|title=Association (<-...->)—Wolfram Language Documentation|website=reference.wolfram.com}}</ref> expression to represent associative arrays.
<syntaxhighlight lang="mathematica">
phonebook = <| "Sally Smart" -> "555-9999",
Line 1,035 ⟶ 1,036:
"J. Random Hacker" -> "553-1337" |>;
</syntaxhighlight>
 
To access:<ref>{{cite web|url=https://reference.wolfram.com/language/ref/Key.html|title=Key—Wolfram Language Documentation|website=reference.wolfram.com}}</ref>
 
<syntaxhighlight lang="mathematica">
phonebook[[Key["Sally Smart"]]]
</syntaxhighlight>
 
If the keys are strings, the ''Key'' keyword is not necessary, so:
 
<syntaxhighlight lang="mathematica">
phonebook[["Sally Smart"]]
</syntaxhighlight>
 
To list keys:<ref>{{cite web|url=https://reference.wolfram.com/language/ref/Keys.html|title=Keys—Wolfram Language Documentation|website=reference.wolfram.com}}</ref> and values<ref>{{cite web|url=https://reference.wolfram.com/language/ref/Values.html|title=Values—Wolfram Language Documentation|website=reference.wolfram.com}}</ref>
 
Keys[phonebook]