View Problem

Remove an entry from a map

Given a map pets {joe:cat,mary:turtle,bill:canary} remove the mapping for "bill" and print "canary"
ExpandDiskEdit
ruby
puts map.delete :bill
DiskEdit
clojure
; Maps are immutable
; The following expression will return a new map without the 'bill key
(let [pets '{joe cat mary turtle bill canary}]
(println (get pets 'bill))
(dissoc pets 'bill))
ExpandDiskEdit
fsharp
let key = "bill"
match (pets |> Map.tryFind key) with
| Some(value) -> pets <- (Map.remove key pets) ; printfn "%s : %s removed" key value
| None -> printfn "Key %s not found" key
ExpandDiskEdit
fsharp
let key = "bill"
let entry = if (pets.ContainsKey(key)) then Some(pets.[key]) ; else None
pets.Remove(key)

match entry with
| Some(value) -> printfn "%s" value
| None -> printfn "key not found"
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if (pets->ContainsKey("bill"))
{
String^ value = safe_cast<String^>(pets["bill"]); pets->Remove("bill");
Console::WriteLine("{0}", value);
}
ExpandDiskEdit
go 1+
fmt.Println(pets["bill"])
delete(pets, "bill")
ExpandDiskEdit
go 0.x
fmt.Println(pets["bill"])
pets["bill"] = "", false
ExpandDiskEdit
groovy
pets = [joe:'cat', mary:'turtle', bill:'canary']
println pets.remove('bill')

Submit a new solution for ruby, csharp, clojure, fsharp ...
There are 16 other solutions in additional languages (erlang, fantom, haskell, java ...)