ToExpression
ToExpression[input]
gives the expression obtained by interpreting strings or boxes as Wolfram Language 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.
Details
- form can be InputForm, StandardForm, TeXForm, TraditionalForm, or MathMLForm.
- ToExpression["string"] uses InputForm interpretation rules.
- ToExpression[boxes] uses StandardForm interpretation rules.
- ToExpression prints a message and returns $Failed if it finds a syntax error. ToExpression does not call $SyntaxHandler. »
- The input given in ToExpression can correspond to multiple Wolfram Language expressions. ToExpression processes each one in turn, just like Get. »
- ToExpression[input,form,Hold] can be used to convert input to an expression, but with the expression wrapped in Hold to prevent evaluation. »
- ToExpression uses any relevant definitions given for MakeExpression.
Examples
open allclose allBasic Examples (5)
Convert a string to an expression, and evaluate the expression:
Interpret a TraditionalForm string:
Convert boxes to Wolfram Language input:
Scope (2)
Convert a string to an expression using TraditionalForm rules:
Convert the same string using StandardForm and InputForm rules:
Convert and evaluate a string representing multiple lines of code:
Generalizations & Extensions (1)
Apply the head Hold to prevent evaluation:
Properties & Relations (2)
ToExpression evaluates the expression, while MakeExpression does not:
Display an InterpretationBox:
The expression is the second argument of the InterpretationBox:
Text
Wolfram Research (1988), ToExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/ToExpression.html (updated 2004).
CMS
Wolfram Language. 1988. "ToExpression." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2004. https://reference.wolfram.com/language/ref/ToExpression.html.
APA
Wolfram Language. (1988). ToExpression. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ToExpression.html