View Problem

Retrieve a value from a map

Given a map pets {joe:cat,mary:turtle,bill:canary} print the pet for "joe" ("cat")
ExpandDiskEdit
ruby
puts map['joe']
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if (pets->ContainsKey("joe")) Console::WriteLine(pets["joe"]);
ExpandDiskEdit
cpp
cout << pets["joe"] << endl;
ExpandDiskEdit
fantom
map := ["joe":"cat", "mary":"turtle", "bill":"canary"]
pet := map["joe"]
echo("pet=$pet")
ExpandDiskEdit
erlang
dict:is_key(joe, Pets) andalso begin io:format("~w~n", [dict:fetch(joe, Pets)]), true end.
ExpandDiskEdit
erlang
case dict:find(joe, Pets) of error -> false ; {ok, Pet} -> io:format("~w~n", [Pet]) end.
ExpandDiskEdit
erlang
IsMember = ets:member(Pets, joe), if (IsMember) -> io:format("~w~n", [ets:lookup_element(Pets, joe, 2)]) ; true -> false end.
ExpandDiskEdit
erlang
case ets:match(Pets, {joe, '$1'}) of [] -> false ; [[Pet]] -> io:format("~w~n", [Pet]) end.
ExpandDiskEdit
erlang
case gb_trees:lookup(joe, Pets) of none -> false ; {value, Pet} -> io:format("~w~n", [Pet]) end.

Submit a new solution for ruby, csharp, cpp, fantom ...
There are 19 other solutions in additional languages (clojure, fsharp, go, groovy ...)