Re: Keeping track of variables used in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg122912] Re: Keeping track of variables used in Mathematica
• From: Dana DeLouis <dana01 at me.com>
• Date: Wed, 16 Nov 2011 04:44:15 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```>   a list of custom variables assigned and used in a current notebook

Hi.  I don't have a great solution for the current notebook.

If I have a first workbook with just :
a = 2;
b = 4;

And then a second (the Current Workbook) with:

c=6;

Names["Global`*"]
{a,b,c}

Then this returns the Global names from ALL workbooks, and not from the Current Workbook. (ie Just c)

There was a suggestion for \$NewSymbol, but I had mixed results.
Did you or anyone else get this idea to work.  Here's what I mean.
At the top of a third workbook, the best I came up with is the following:

NewNames={};
\$NewSymbol=AppendTo[NewNames,#1]&;

d=3;
e=Range[4];

(* Global has everything *)

Names["Global`*"]
{a,b,c,d,e,NewNames}

(* But NewNames just had d & e, which seems like what we want *)

NewNames
{d,e}

\$NewSymbol=.

However, one of the drawbacks seems to be that if you recalculate the workbook, then NewNames is reset to {}, and nothing is added since the symbols (d & e) already exists.
Does anyone know of the better way to use this function in this manner?

If I start yet another workbook, then this is perhaps another option.

e=7;
f=Range@10;
Block[{x,y,z}, y=5.5];
g[x_]:=x^2

Union[Flatten[Apply[List,Extract[First[Apply[List,NotebookGet[],{1}]],Position[First[Apply[List,NotebookGet[],{1}]],RowBox[{_,"=",_}],\[Infinity]]],{1}],1][[All,1]]]

{e,f,y}

Names["Global`*"]
{a,b,c,d,e,f,g,NewNames,x,y,z}

Here, g,x,y,z became global variables,  but the above code only picked up
e,f,y  as they were assigned values - within this current notebook.

This is not fully tested of course.
Perhaps there are better ways ???

= = = = = = = = =
Here are the steps I used above.
I combined them above to remove the variables.
I didn't want to mix these variables with the workbook variables.

t=First[Apply[List,NotebookGet[],{1}]];

pos=Position[t,RowBox[{_,"=",_}],\[Infinity]];

Union[Flatten[Apply[List,Extract[t,pos],{1}],1][[All,1]]]

= = = = = = = = =
HTH  :>)
Dana DeLouis
= = = = = = = = =

On Nov 10, 6:56 am, Mark <big.d... at att.net> wrote:
> Hello community:
>
> Does Mathematica have a command that will output or compute a list of custom variables assigned and used in a current notebook / Mathematica session?
>
> If so, what is the command / expression?