Re: local variables
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: local variables
- From: TODD GAYLEY <TGAYLEY at ccit.arizona.edu>
- Date: 29 Sep 1992 22:44:12 -0700 (MST)
John Pender (tuk at natazhat.uafphys.alaska.edu) asks: > hi guys- > i'm forwarding an inquiry from one of my students. in particular, is there > an mma function that returns a list of all the variables you've defined in a > session and their values? thanks in advance. The function Names["Global`*"] will return a list of the names (as strings) of all variables defined in the Global` context. From there, you can do what you want. For example, for a primitive printout of variables and values, you could use: Print[# <> " = " <> ToString[ToExpression[#]]]& /@ Names["Global`*"]; This won't show the definitions of functions, however. For example, if you have defined f[x_] := something, then the printout will include the line f = f because the symbol f, all by itself, has not been given a value. An alternative is to use (Print[#]; Information[#]; Print["\n"])& /@ Names["Global`*"]; This will show more about each symbol, including defs for functions, but it is much slower. --Todd ----------------------------------------------------------------- Todd Gayley Department of Ecology and Evolutionary Biology University of Arizona tgayley at ccit.arizona.edu -or- tgayley at cs.arizona.edu