Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6466

Re: Keeping track of variables used in Mathematica

From Dana DeLouis <dana01@me.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Keeping track of variables used in Mathematica
Date 2011-11-16 09:46 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ja00p0$61k$1@smc.vnet.net> (permalink)

Show all headers | View raw


>   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...@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?
> Thanks in advance
> Mark


Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Keeping track of variables used in Mathematica Dana DeLouis <dana01@me.com> - 2011-11-16 09:46 +0000
  Re: Keeping track of variables used in Mathematica David Bailey <dave@removedbailey.co.uk> - 2011-11-17 12:03 +0000

csiph-web