# Are symbols automatically generated when defining a variable in the global context and what are symbols?

Abstract: I have noticed something really tricky with Mathematica and the documentation for symbols is short on clearing the confusion. It likely reveals what symbols are but it's not very prominent. I know unique symbols are created inside Modules but are they also generated every time we define regular functions and variables?

About The Code: I did a simple test with abc = 123. The output for ?abc gives a grayed out Symbol and SymbolName produces an error message. Does this mean it is not a symbol?

abc = 123
?abc
SymbolName[abc]


Four Questions:

1. Are system functions symbols?
2. Are user defined functions symbols?
3. Are user defined variables symbols?
4. What are symbols and are they automatically generated?

Towards your abc example which seems to be the source of confusion: At all times after evaluating abc = 123, abc is a symbol (with full name probably Globalabc, but that depends on the Context[] in which you evaluate it). The problem with SymbolName[abc] is that abc evaluates immediately to 123. The latter is not a symbol, hence SymbolName[123] throws an error. One can obtain the behavior that you probably expected as follows:
SymbolName[Unevaluated[abc]]

• Addendum: if you want to use that construct as a pure function, do it this way: ff = Function[Null, SymbolName[Unevaluated[#]], {HoldFirst}]; ff[abc]. – J. M.'s ennui May 31 '20 at 12:45
• @J.M. could it be used in this form as well: ff@abc? Does this form omit the need to set attributes to HoldFirst when used in other contexts like Blocks or user defined functions? Question on the immediate assignment ff = . Shouldn't it be delayed assignment ff := ? – Jules Manson Jun 1 '20 at 5:34
• @Jules: 1. yes; the attributes are already associated with the pure function ff. 2. := would force repeated evaluation of the RHS, so that isn't what you want in that situation; =` is the correct choice here. – J. M.'s ennui Jun 1 '20 at 5:37