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

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

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


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

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

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


(* 0 *)
  • $\begingroup$ Perfect, thanks! $\endgroup$ – ssch Jan 21 '13 at 19:49
  • $\begingroup$ @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. $\endgroup$ – Leonid Shifrin Jan 22 '13 at 10:14
  • $\begingroup$ @Stefan Long experience... :-). This particular issue is covered in Mathematica book and also David Wagner's book on Mathematica programming. $\endgroup$ – Leonid Shifrin Jan 23 '13 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.