WOLFRAM LANGUAGE TUTORIAL
Intercepting the Creation of New Symbols
The Wolfram Language creates a new symbol when you first enter a particular name. Sometimes it is useful to "intercept" the process of creating a new symbol. The Wolfram Language provides several ways to do this.
|On[General::newsym]||print a message whenever a new symbol is created|
|Off[General::newsym]||switch off the message printed when new symbols are created|
Printing a message when new symbols are created.
This tells the Wolfram Language to print a message whenever a new symbol is created.
The Wolfram Language now prints a message about each new symbol that it creates.
This switches off the message.
Generating a message when the Wolfram Language creates a new symbol is often a good way to catch typing mistakes. The Wolfram Language itself cannot tell the difference between an intentionally new name, and a misspelling of a name it already knows. But by reporting all new names it encounters, the Wolfram Language allows you to see whether any of them are mistakes.
|$NewSymbol||a function to be applied to the name and context of new symbols which are created|
Performing operations when new symbols are created.
When the Wolfram Language creates a new symbol, you may want it not just to print a message, but instead to perform some other action. Any function you specify as the value of the global variable $NewSymbol will automatically be applied to strings giving the name and context of each new symbol that the Wolfram Language creates.
This defines a function to be applied to each new symbol which is created.
The function is applied once to v
and once to w