13.07.2015 Views

Mathematica Tutorial: Notebooks And Documents - Wolfram Research

Mathematica Tutorial: Notebooks And Documents - Wolfram Research

Mathematica Tutorial: Notebooks And Documents - Wolfram Research

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Notebooks</strong> and <strong>Documents</strong> 105ToExpression will attempt to interpret any string as <strong>Mathematica</strong> input. But if you give it astring that does not correspond to syntactically correct input, then it will print a message, andreturn $Failed.This is not syntactically correct input, so ToExpression does not convert it to an expression.In[16]:= ToExpression@"1 +ê+ 2"DToExpression::sntx: Syntax error in or before "1 +/+ 2".^Out[16]= $FailedToExpression requires that the string correspond to a complete <strong>Mathematica</strong> expression.In[17]:= ToExpression@"1 + 2 + "DToExpression::sntxi:Incomplete expression; more input is needed.Out[17]= $FailedYou can use the function SyntaxQ to test whether a particular string corresponds to syntacticallycorrect <strong>Mathematica</strong> input. If SyntaxQ returns False, you can find out where the erroroccurred using SyntaxLength. SyntaxLength returns the number of characters which weresuccessfully processed before a syntax error was detected.SyntaxQ shows that this string does not correspond to syntactically correct <strong>Mathematica</strong> input.In[18]:= SyntaxQ@"1 +ê+ 2"DOut[18]= FalseSyntaxLength reveals that an error was detected after the third character in the string.In[19]:= SyntaxLength@"1 +ê+ 2"DOut[19]= 3Here SyntaxLength returns a value greater than the length of the string, indicating that theinput was correct so far as it went, but needs to be continued.In[20]:= SyntaxLength@"1 + 2 + "DOut[20]= 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!