MathGroup Archive 2000

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

Search the Archive

Re: Evaluate a string

  • To: mathgroup at
  • Subject: [mg25162] Re: Evaluate a string
  • From: "P.J. Hinton" <paulh at>
  • Date: Tue, 12 Sep 2000 02:58:48 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <8pfe7f$>
  • Sender: owner-wri-mathgroup at

On 10 Sep 2000, Phlip wrote:

> The inner problem. In Perl, for example, you can evaluate a string back
> in thru the Perl parser:
>     my x = 0;
>     eval "x = 3";
>     assert (x == 3);
> I have a string containing Mathematica language code. How do I evaluate
> it as a Mathematica statement?

Use ToExpression[]. 

In[1]:= ToExpression["foo = 3"]

Out[1]= 3

In[2]:= ? foo

foo = 3

> Taking the code out of the string is not an option. (But I could
> conceivably write the string to a file, and then Load or Run this. But
> I can't find a Mathematica command to load a file and execute it.)

That would be the Get[] command, oftentimes abbreviated as the prefix
operator "<<".  The Run[] function tells the kernel to execute an external
operating system command (like system() in C).

P.J. Hinton
User Interface Programmer                         paulh at
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.

  • Prev by Date: Re: Add the Logarithms (error in integral)
  • Next by Date: CellAutoDelete
  • Previous by thread: Evaluate a string
  • Next by thread: Re: Evaluate a string