Re: Keeping track of variables used in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg122944] Re: Keeping track of variables used in Mathematica
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Thu, 17 Nov 2011 07:02:47 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <ja00p0$61k$1@smc.vnet.net>
On 16/11/2011 09:46, Dana DeLouis wrote:
>
> There was a suggestion for $NewSymbol, but I had mixed results.
I made that suggestion
> 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]&;
You could try:
If[! ValueQ[NewNames],NewNames={}]
This will only set it once, even if you re-evaluate the notebook. (BTW,
you really should avoid fully capitalised names like NewNames - such
names are reserved for future Wolfram functions).
I would also restrict the collection to global symbols:
$NewSymbol=If[#2=="Global`",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 *)
I am wondering if the other symbols were spuriously added by some
packages that get loaded in your environment. I usually pre-load some
packages, but on a bare mathematica, the Global context appears to be empty.
>
Extracting the names from the BoxForm in a notebook doesn't seem very
useful to me - because it doesn't pick up the context of symbols with an
implicit context.
David Bailey
http://www.dbaileyconsultancy.co.uk