"HeldExpression" (Interpreter Type)
Wolfram Language expression.
Details
- "HeldExpression" can be used in Interpreter and related constructs, including deployed smart form fields.
- Use of "HeldExpression" does not require connectivity to the Wolfram Cloud.
- "HeldExpression" keeps its result unevaluated by wrapping it in HoldComplete.
Restriction Specifications
-
Restricted["HeldExpression",{{choice1,…}}] one among choices Restricted["HeldExpression",symbols] an expression involving only the given symbols (All, Automatic, or an explicit list) Restricted["HeldExpression",symbols,contexts] an expression involving only the given symbols or symbols in the given contexts (All, Automatic, or an explicit list) Restricted["HeldExpression",symbols,contexts,resultcontext] an expression involving only the given symbols or symbols in the given contexts, where the new symbols are created in resultcontext
Interpretation
- "HeldExpression" yields a Wolfram Language expression wrapped in HoldComplete.
Examples
Basic Examples (5)
Interpret expressions and avoid evaluation:
Interpreter["HeldExpression"]["1/2 + 3/5 - 2/3"]Interpreter["HeldExpression"]["Cos[Pi]"]No evaluation is attempted when matching the choices:
Interpreter[Restricted["HeldExpression", {{1, 2, 3, 4}}]]["2+1"]Interpreter[Restricted["HeldExpression", {{2, HoldComplete[2 + 1]}}]]["2+1"]By default, only expressions with no side effect are allowed:
Interpreter["HeldExpression"]["Quit[]"]This can be changed by allowing All symbols:
Interpreter[Restricted["HeldExpression", All]]["Quit[]"]Restrict to a list of symbols:
Interpreter[Restricted["HeldExpression", {Map, List, Function, Slot}]]["#&/@{1,2,3}"]Interpreter[Restricted["HeldExpression", {Map, List, Function, Slot}]]["#+1&/@{1,2,3}"]By default, new symbols are created in $Context, but a custom context can be specified:
Interpreter[Restricted["HeldExpression", Automatic, Automatic, Automatic]]["x"]
Context[x]Interpreter[Restricted["HeldExpression", Automatic, Automatic, "mycontext`"]]["y"]
Context[y]See Also
Interpreter Restricted Failure HoldComplete
Interpreter Types: Expression InactiveExpression SemanticExpression HeldSemanticExpression InactiveSemanticExpression
Related Guides
History
Introduced in 2014 (10.0)