MSPToExpression

MSPToExpression[var]
interprets the variable var
uses the format fmt to interpret var
returns the result wrapped in head

DetailsDetails

  • MSPToExpression is the webMathematica version of ToExpression; it provides the same functionality for turning strings into Mathematica input, but it also carries out a security check.
  • You should always use MSPToExpression rather than ToExpression in your code because it provides additional security.
  • The following exceptions can be thrown by MSPToExpression.
  • MSPException["ParseError"]if the value cannot be interpreted by Mathematica
    MSPException["SecurityError"]if the value does not pass the security test
    MSPException["ValueError"]if the value is not a string, this indicates a programmatic error by the page author
    MSPException["NoValueError"]if the variable does not have a value, this indicates a programmatic error by the page author
    MSPException["VariableError"]if the variable is not a Mathematica symbol, this indicates a programmatic error by the page author

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

You can simulate how the function works by installing and loading the package and setting the security content.

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input

Here the variable $$var is assigned to the value "5+7"; note that the value is a string.

In[3]:=
Click for copyable input

When MSPToExpression evaluates, the parsed value of $$var is returned.

In[4]:=
Click for copyable input
Out[4]=

If a variable has no value, an MSPException is thrown.

In[5]:=
Click for copyable input
Out[5]=

Like ToExpression, MSPToExpression can take a format type for interpretation.

In[6]:=
Click for copyable input
Out[6]=

If the input value cannot be interpreted, an MSPException is thrown.

In[7]:=
Click for copyable input
Out[7]=

If the input value does not pass the security test, an MSPException is thrown.

In[8]:=
Click for copyable input
Out[8]=

Input can also be given in MathML.

In[9]:=
Click for copyable input
In[10]:=
Click for copyable input
Out[10]=
New to Mathematica? Find your learning path »
Have a question? Ask support »