Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to get a listing of currently defined symbols

  • To: mathgroup at
  • Subject: [mg36869] Re: How to get a listing of currently defined symbols
  • From: "Allan Hayes" <hay at>
  • Date: Mon, 30 Sep 2002 03:03:13 -0400 (EDT)
  • References: <an3pp2$ofk$>
  • Sender: owner-wri-mathgroup at

"fjolsvit" <fjolsvit at> wrote in message
news:an3pp2$ofk$1 at
> 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


Make some entries, notice that b, x and y have no definitions - they are
simply created.

    p= 3x +1;

We can find all the symbols we have created so far.



Actually, they are the strings of the symbols (otherwise, for example, a
would immediately evaluate to 3).


        {"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];

      Or[DownValues@@#=!={}, UpValues@@#=!={},OwnValues@@#=!={},
        ToExpression[x, InputForm, Hold]]

    definedQ[x_]:= definedQ[Evaluate[ToString[Unevaluated[x]]]]

Using this we get

    Select[Names["`*"], definedQ]


To get information about the symbols

Information/@Select[Names["`*"], definedQ];


        a = 3


        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[


            f[y_] := y^2


            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 Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

  • Prev by Date: RE: Accuracy and Precision
  • Next by Date: Re: Are configuration & UI better in 4.2?
  • Previous by thread: Re: How to get a listing of currently defined symbols
  • Next by thread: Some General Questions about Mathematica