Message Boards Message Boards

0
|
4076 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How is a list of program variables generated in a large program?

I have some large programs and tend to make subtle spelling mistakes in large variable names. Sometimes these error takes days to find. A list of variable used in these programs would save a lot of time and make debugging much easier. I can not find such a program or function in Mathematica or on the community form. Thanks for any help.

4 Replies

Rohit, Thanks again, I closed and saved the program, and then reopened it. All three techniques now return lists of variables:

 1. Names["Global`*"]
 2. Names[Context[] <> "*"]
 3. Names["Global`@*"] 

Only #3 returns all the correct variables that I have used in the program. Item #1 and #2, both return the correct variables, but also hundreds of obscure, built-in function that I have never called ( or heard of ). The information is not useful because of the large amount of spurious information. Tony

Thanks for for your suggestions:

  • The undefined symbols feathers built-in Mathematica does help a lot. Perhaps if I change the color of the resulting variable, it may be better for me.
  • Your suggestions were helpful. I tried using Names["Global@*"], as well as Names["Global*"]. I am not sure of the difference. But, neither technique provided a list of variables.
  • A function list button should be built-in Mathematica in the "Debugging" dropdown. I would help identify names that are similar and help maintain large programs even if all are internally defined.

Thanks again for you help. Your thoughts opened another way to look at my problem.

Posted 4 years ago

The backtick ` before the * is needed. Copy and paste the following

Names["Global`*"]

If you still get an empty list, perhaps your current context is not Global. Try

Names[Context[] <> "*"]
POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hi Anthony,

If you reference an undefined symbol, the notebook interface will highlight it so it is easy to spot. If you are trying to find all symbols defined in another notebook you can do something like this

symbols = Names["Global`*"]; (* Currently defined symbols in the Global context *)
NotebookEvaluate[FileNameJoin[{NotebookDirectory[], "test.nb"}], InsertResults -> False];
Complement[Names["Global`*"], symbols] (* New symbols in the Global context after evaluating notebook *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract