[Date Index] [Thread Index] [Author Index]
Re: Evaluate a string
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:= ToExpression["foo = 3"] Out= 3 In:= ? foo Global`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.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.