Re: How to get a listing of currently defined symbols

*To*: mathgroup at smc.vnet.net*Subject*: [mg36869] Re: How to get a listing of currently defined symbols*From*: "Allan Hayes" <hay at haystack.demon.co.uk>*Date*: Mon, 30 Sep 2002 03:03:13 -0400 (EDT)*References*: <an3pp2$ofk$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

"fjolsvit" <fjolsvit at netscape.net> wrote in message news:an3pp2$ofk$1 at smc.vnet.net... > IIRC, there is a way to get a list of all the symbols defined in the > currently running session. I can't seem to find the reference to that > command. Could somone point me in the direction of documentation which > will tell me how to get information about the current session? > > > TIA, > Let's begin with a fresh session Quit Make some entries, notice that b, x and y have no definitions - they are simply created. a=3; b; p= 3x +1; f[y_]:=y^2; We can find all the symbols we have created so far. Names["`*"] {a,b,f,p,x,y} Actually, they are the strings of the symbols (otherwise, for example, a would immediately evaluate to 3). InputForm[%] {"a", "b", "f", "p", "x", "y"} How can we take out the strings of the undefined symbols? I make a function that test if the symbol has been defined (or has an attribute assigned): SetAttributes[definedQ, HoldFirst]; definedQ[x_String]:= Or[DownValues@@#=!={}, UpValues@@#=!={},OwnValues@@#=!={}, SubValues@@#=!={},DefaultValues@@#=!={},NValues@@#=!={}, Attributes@@#=!={}]&[ ToExpression[x, InputForm, Hold]] definedQ[x_]:= definedQ[Evaluate[ToString[Unevaluated[x]]]] Using this we get Select[Names["`*"], definedQ] {a,definedQ,f,p} To get information about the symbols Information/@Select[Names["`*"], definedQ]; a a = 3 definedQ Attributes[definedQ] = {HoldFirst} definedQ[x_String] := (DownValues @@ #1 =!= {} || UpValues @@ #1 =!= {} || OwnValues @@ #1 =!= {} || SubValues @@ #1 =!= {} || DefaultValues @@ #1 =!= {} || NValues @@ #1 =!= {} & )[ToExpression[x, InputForm, Hold]] definedQ[x_] := definedQ[Evaluate[ ToString[Unevaluated[x]]]] f f[y_] := y^2 p p = 1 + 3*x I have assumed that you are interested only in the symbols in the symbols in the default context "Global`". Other context can be provided for. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565