# Check if symbol is in core language

How can I check if a symbol is pre-defined by Mathematica, in a way that's backwards compatible with old versions?

i.e. I would like some CoreLanguageQ[x_Symbol] which matches CoreLangaugeQ[Print], but not CoreLanguageQ[f]

Then it can be used to help make code backwards compatible, eg.

If[!CoreLanguageQ[Echo], Echo[x_]:= (Print[x];x)]


Thank you.

• Maybe something like CoreLanguageQ[x_Symbol] := Context[x]==="System" ? Jun 19 '18 at 1:05
• Mathematica's "core language" is ill defined. As @QuantumDot notes, the best you can probably do is check whether a symbol is in the "System" context. Package development aspects of the language weren't terribly well designed so the language is somewhat bloated in this regard. It does not have a tight "core language" like most modern languages. Jun 19 '18 at 1:42
• My definition is 'any symbol that's defined when I restart the kernel'. I will try System, thankyou.
– Joe
Jun 19 '18 at 19:05

You can look it up using WolframLanguageData, which has a list of all pre-defined symbols:

ClearAll[CoreLanguageQ]
SetAttributes[CoreLanguageQ, HoldAll]
CoreLanguageQ[x_] := With[{name = SymbolName[x]}, CoreLanguageQ[name]]
CoreLanguageQ[x_String] := With[{
names = WolframLanguageData[All, "Name"]
}, MemberQ[names, x]]

CoreLanguageQ[Plot]
(* Out: True *)

CoreLanguageQ[Plott]
(* Out: False *)


Looking at the context of the symbol is also a viable approach. However, the WolframLanguageData approach is appealing because the documentation states that

WolframLanguageData[] gives a list of all Wolfram Language symbols.

Which is to say, the list returned by this function is by definition Wolfram Language. This is as close as a definition of "core language" that we can come.

For the problem in the updated question, it would seem appropriate to check if a symbol exists in the System context like QuantumDot suggests in a comment.

The only backward compatible way to use this would be to create lists of functions available for specific versions and include them in your code. For example:

names = WolframLanguageData[All, "Name"];
versionIntroduced = WolframLanguageData[All, "VersionIntroduced"];
allowed = Pick[names, Thread[versionIntroduced <= 10]];


In this code, allowed holds all the symbols that exist in version 10, presuming that no symbol previously introduced was removed.

• Ah I apologise. This answers my original question, but now I see that my original question wasn't what I wanted to ask. WolframLanguageData[] is a relatively new function and I want to use this for backwards compatability; eg. If[!CoreLanguageQ[Echo], Echo[x_]:= (Print[x];x)]. I've updated my question
– Joe
Jun 19 '18 at 19:03
• @Joe ok, then QuantumDot's suggestion seems more appropriate. Jun 19 '18 at 19:29
• Yes I think so. Thankyou for your solution though it's nice
– Joe
Jun 20 '18 at 17:17