OpenersNotesSection(Spacer1)Details

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (7)

Interpret expressions and avoid evaluation:

Interpreter["InactiveExpression"]["Sin[Pi/2]"]

Interpreter["InactiveExpression"]["3+2"]

No evaluation is attempted when matching the choices:

Interpreter[Restricted["InactiveExpression",{{1,2,3,4}}]]["2+1"]

Interpreter[Restricted["InactiveExpression",{{2, Inactivate[2+1]}}]]["2+1"]

By default, only expressions with no side effect are allowed:

Interpreter["InactiveExpression"]["Quit[]"]

This can be changed by allowing (RefLink[All, paclet:ref/All]) symbols:

Interpreter[Restricted["InactiveExpression", All]]["Quit[]"]

Restrict to a list of symbols:

Interpreter[Restricted["InactiveExpression",{Map,List,Function,Slot}]]["#&/@{1,2,3}"]

Interpreter[Restricted["InactiveExpression",{Map,List,Function,Slot}]]["#+1&/@{1,2,3}"]

By default, new symbols are created in (RefLink[$Context, paclet:ref/$Context]), but a custom context can be specified:

var=Interpreter[Restricted["InactiveExpression",Automatic,Automatic,Automatic]]["x"]
Context[Evaluate[var]]

var=Interpreter[Restricted["InactiveExpression",Automatic,Automatic,"mycontext`"]]["x"]
Context[Evaluate[var]]

Specify contexts for the allowed and output symbols:

mycontext`x=10;
Interpreter[Restricted["InactiveExpression",Automatic,{"mycontext`","System`"},"mycontext`"]]["y = x + 1"]

Prevent the creation of any new symbol:

Interpreter[Restricted["InactiveExpression",Automatic,Automatic,None]]["3+1"]

Interpreter[Restricted["InactiveExpression",Automatic,Automatic,None]]["z+1"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Interpreter, paclet:ref/Interpreter])  ▪  (RefLink[Restricted, paclet:ref/Restricted])  ▪  (RefLink[Failure, paclet:ref/Failure])  ▪  (RefLink[Inactive, paclet:ref/Inactive])  ▪  (RefLink[Inactivate, paclet:ref/Inactivate])}, {Related Interpreter Types:  (RefLink[Expression, paclet:ref/interpreter/Expression])  ▪  (RefLink[HeldExpression, paclet:ref/interpreter/HeldExpression])  ▪  (RefLink[SemanticExpression, paclet:ref/interpreter/SemanticExpression])  ▪  (RefLink[HeldSemanticExpression, paclet:ref/interpreter/HeldSemanticExpression])  ▪  (RefLink[InactiveSemanticExpression, paclet:ref/interpreter/InactiveSemanticExpression])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Setting Up Input Interpreters, paclet:guide/InterpretingStrings])}})}})