For convenience I'm trying to add an extra property to CountryData

Unprotect[CountryData];
CountryData[c_String, "MyProperty"] := 0; (* actually call to another function *)
Protect[CountryData];


But when using it I get:

CountryData["Greenland", "MyProperty"]


CountryData::notprop: "!(\"\\"MyProperty\\"\") is not a known property for CountryData. Use CountryData[\"Properties\"] for a list of properties."

What's the right way to do this?

There is high probability this is a duplicate, but I wasn't able to find how to do this, sorry in advance

-
Tangentially related: mathematica.stackexchange.com/q/2793/121 –  Mr.Wizard Jan 21 '13 at 19:54

This is a matter of rules ordering for CountryData definitions. You have to do something like this:

Unprotect[CountryData];
CountryData[c_String, "MyProperty"] := 0;
(*actually call to another function*)
DownValues[CountryData] = RotateRight[DownValues[CountryData]];
Protect[CountryData];


This reorders the definitions so that yours is at the top (or close to the top). Then:

CountryData["Greenland","MyProperty"]

(* 0 *)

-
Perfect, thanks! –  ssch Jan 21 '13 at 19:49
@ssch Was glad to help. I think I've run into exactly such problem with ...Data before. Also a good example of when manual rule reordering is really needed. Thanks for the accept. –  Leonid Shifrin Jan 22 '13 at 10:14
@Leonid Shifrin from where do you know all that stuff!? Pretty impressing.manual rule reordering ... No shit Sherlock ;) –  Stefan Jan 22 '13 at 20:06
@Stefan Long experience... :-). This particular issue is covered in Mathematica book and also David Wagner's book on Mathematica programming. –  Leonid Shifrin Jan 23 '13 at 10:21