"Expression" (Interpreter Type)
Wolfram Language expression.
Details
- "Expression" can be used in Interpreter and related constructs, including deployed smart form fields.
- Use of "Expression" does not require connectivity to the Wolfram Cloud.
Restriction Specifications
-
Restricted["Expression",{{choice1,…}}] one among choices Restricted["Expression",symbols] an expression involving only the given symbols (All, Automatic, or an explicit list) Restricted["Expression",symbols,contexts] an expression involving only the given symbols or symbols in the given contexts (All, Automatic, or an explicit list) Restricted["Expression",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
- "Expression" can yield any Wolfram Language expression.
Examples
Basic Examples (7)
Interpreter["Expression"]["3+2"]Interpreter["Expression"]["Sin[Pi/2]"]Restrict to a list of choices:
Interpreter[Restricted["Expression", {{1, 2, 3}}]][{"4/2", "2+1", "1", "2*3"}]By default, only expressions with no side effect are allowed:
Interpreter["Expression"]["f[x_] := x+2"]
f[1]This can be changed by allowing All symbols:
Interpreter[Restricted["Expression", All]]["f[x_] := x+2"]
f[1]Restrict to a list of symbols:
Interpreter[Restricted["Expression", {Map, List, Function, Slot}]]["#&/@{1,2,3}"]Interpreter[Restricted["Expression", {Map, List, Function, Slot}]]["#+1&/@{1,2,3}"]By default, new symbols are created in $Context, but a custom context can be specified:
var = Interpreter[Restricted["Expression", Automatic, Automatic, Automatic]]["x"]
Context[Evaluate[var]]var = Interpreter[Restricted["Expression", Automatic, Automatic, "mycontext`"]]["x"]
Context[Evaluate[var]]Specify contexts for the allowed and output symbols:
Global`x = 10;
Interpreter[Restricted["Expression", Automatic, {"Global`", "System`"}, "Global`"]]["y = x + 1"]Prevent the creation of any new symbol:
Interpreter[Restricted["Expression", Automatic, Automatic, None]]["3+1"]Interpreter[Restricted["Expression", Automatic, Automatic, None]]["z+1"]See Also
Interpreter Restricted Failure
Interpreter Types: HeldExpression InactiveExpression SemanticExpression HeldSemanticExpression InactiveSemanticExpression
Related Guides
History
Introduced in 2014 (10.0)