Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*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 2000

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

Search the Archive

Re: Evaluate a string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25174] Re: Evaluate a string
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 12 Sep 2000 21:24:20 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <8pfe7f$d1b@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

> 
> The inner problem. In Perl, for example, you can evaluate a string back
> in thru the Perl parser:

?ToExpression

"ToExpression[input] gives the expression obtained by interpreting
strings or \
boxes as Mathematica input. ToExpression[input, form] uses
interpretation \
rules corresponding to the specified form. ToExpression[input, form, h]
wraps \
the head h around the expression produced before evaluating it."

In[]:= x = 0;
       ToExpression["x=3"];
       x

Out[]= 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.)
> 

Ok lets use a file:

In[]:=Put[OutputForm[tstring], "/tmp/test.m"];
In[]:=Get["/tmp/test.m"]

Out[]= y^2

MLEvaluateString() is not a real ML function ?

A simple look into the C-code show, there is the infamous
ToExpression call again, together with a EvaluatePacket so
that the expression gets evaluated by the kernel.

int MLEvaluate( mlp, s)
	MLINK mlp;
	charp_ct s;
{
	if( MLAbort) return 0;
	return MLPutFunction( mlp, "EvaluatePacket", 1L)
		&& MLPutFunction( mlp, "ToExpression", 1L)
		&& MLPutString( mlp, s)
		&& MLEndPacket( mlp);
} /* MLEvaluate */

Evaluate string make nothing than to wait
for the answer. 

int MLEvaluateString( MLINK mlp, charp_ct s)
{
	int pkt;
	if( MLAbort) return 0;
	if( MLEvaluate( mlp, s)){
		while( (pkt = MLAnswer( mlp), pkt) && pkt != RETURNPKT)
			MLNewPacket( mlp);
		MLNewPacket( mlp);
	}
	return MLError( mlp) == MLEOK;
} /* MLEvaluateString */

There is no additional dependence and it seems to be easy to copy both
functions.
You should somewehere have a MLAbort variable in your program.

It shold be simple to rewrite the functions in perl if you have access
to MLPutString() and MLPutFunction().

> 
> Where is the optimal path thru all this to some simple environmental
> features that all other languages have???

The optimal path should be reading "The Mathematica Book" by S. Wolfram
that came with your Mathematica copy. 

Regards
  Jens


  • Prev by Date: Re: CellAutoDelete
  • Next by Date: Re: When ploting a differential equation, sigularities cause big ugly vertical lines on the graph - how can I get rid of them? By some magic mathematica incantaion?
  • Previous by thread: Re: Evaluate a string
  • Next by thread: what are some good web sites for learning more about programming mathematica for a programmer who's relearning his math...