# How to get all the symbols x for which f[x] is defined?

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?

• Try First[#][[1, 1]] & /@ DownValues[f]. Commented May 1, 2015 at 5:08
• Equivalent to Level[DownValues[f], {4}]. Commented May 1, 2015 at 5:19
• @Virgil. Nice, but not always equivalent. Try f[alpha]={{beta}}. Then Level[DownValues[f], {4}] returns {alpha, beta}. Commented May 1, 2015 at 6:49
• @Virgil This DownValues[f][[All, 1, 1, 1]] will behave slightly faster for large DownValues. Commented May 1, 2015 at 7:09
• @FredSimons: good point. Commented May 1, 2015 at 12:50

## 1 Answer

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} *)