Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Saving all user-defined variables

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg489] Saving all user-defined variables
  • From: Ed_Donley <HEDONLEY at grove.iup.edu>
  • Date: Thu, 23 Feb 1995 17:37:06 -0500 (EST)

I would like to save all user-defined variables to a file.  Dump will save the
*entire* state of a Mathematica session, including system-defined variables.  I
would like to use Contexts and Save to only save variables in contexts that
typical users are likely to modify.  My attempt, shown below, doesn't work
because Save expects all but its first argument to be of type Symbol.  In my
code, userVariables is a list of Strings rather than a list of Symbols.  How do
I change a String head to a Symbol head?  Or if this cannot be done, is there
some other way to save all user-defined variables?  Speed and disk space are
issues, so I do not want to use Dump.  I thought I remembered seeing an answer
to this question several years ago, so I searched through the MathGroup
archives.  Unfortunately, it came up empty.

(* First create some user-defined variables *)
In[1] :=
  x = 3;
  y = 4;
  z = 5;
  newcontext`x = 6;
  newcontext`y = 7;

In[6] :=
  contexts = Contexts[]
Out[6] =
  {"DSolve`", "FE`", "Format`", "Global`", "Graphics`Animation`",
   "Graphics`Private`", "Integrate`", "Limit`", "newcontext`",
   "NullSpace`", "Obsolete`", "Series`", "Solve`", "System`",
   "System`ComplexExpand`", "System`Private`"}

In[7] :=
  systemContexts =
  {"DSolve`", "FE`", "Format`", "Graphics`Animation`",
   "Graphics`Private`", "Integrate`", "Limit`",
   "NullSpace`", "Obsolete`", "Series`", "Solve`",
   "System`", "System`ComplexExpand`",
   "System`Private`"};

In[8] :=
  userContexts = Complement[contexts, systemContexts]
Out[8] =
  {"Global`", "newcontext`"}

In[9] :=
  userVariables =
    Complement[
      Flatten[Map[Names[StringJoin[#,"*"]]&, userContexts]],
      {"contexts","systemContexts","userContexts",
       "userVariables"}
    ]
Out[9] =
  {"newcontext`x", "newcontext`y", "x", "y", "z"}

In[10] :=
  Apply[Save, Prepend[userVariables, "savefile"]]

  Save::sym: Argument newcontext`x at position 2
       is expected to be a symbol.
Out[10] =
  Save["savefile", "newcontext`x", "newcontext`y", "x", "y", "z"]


Thanks for your help,
Ed Donley
Mathematics Department
Indiana University of Pennsylvania
Indiana, PA  15705
U.S.A.

hedonley at grove.iup.edu
http://www.ma.iup.edu/MathDept/Professors/HDonley.html


  • Prev by Date: Graphics Guidebook Testimonial
  • Previous by thread: Graphics Guidebook Testimonial