5

Assume that definitions like the following are in place:

f[alpha] = "artichoke";
f[bravo] = "beet";
f[charlie] = "celery";
...
f[yankee] = "yam";
f[zulu] = "zucchini";

etc. (Also assume that all the symbols alpha, bravo, charlie, ..., yankee, zulu evaluate to themselves.)

I'm looking for a way to get a list of all the symbols for which f is defined. IOW, given f, I'm looking for a way to get the list of symbols

{alpha, bravo, charlie, ..., yankee, zulu}

(Note that, for the query I'm interested in here, the values associated with the definitions are irrelevant.)

The closest I've found is to somehow scrape the output of Information[f] (or Definition[f]), which strikes me as a horrible prospect.

Is there a more civilized approach?

kjo
  • 11,717
  • 1
  • 30
  • 89

1 Answers1

4

Barbarism can be avoided through judicious application of DownValues. Using RolfMertig's suggestion, you can get what you want with

f[alpha] = "artichoke";
f[bravo] = "beet";
f[charlie] = "celery";
...
f[yankee] = "yam";
f[zulu] = "zucchini";

DownValues[f][[All, 1, 1, 1]]

(* -> {alpha, bravo, charlie, ..., yankee, zulu} *)
Virgil
  • 3,437
  • 16
  • 27