Re: Evaluate a string
- To: mathgroup at smc.vnet.net
- Subject: [mg25162] Re: Evaluate a string
- From: "P.J. Hinton" <paulh at wolfram.com>
- Date: Tue, 12 Sep 2000 02:58:48 -0400 (EDT)
- Organization: Wolfram Research, Inc.
- References: <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
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.