OpenersNotesSection(Spacer1)Details

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (7)

Interpret expressions:

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 (RefLink[All, paclet:ref/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 (RefLink[$Context, paclet:ref/$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"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Interpreter, paclet:ref/Interpreter])  ▪  (RefLink[Restricted, paclet:ref/Restricted])  ▪  (RefLink[Failure, paclet:ref/Failure])}, {Related Interpreter Types:  (RefLink[HeldExpression, paclet:ref/interpreter/HeldExpression])  ▪  (RefLink[InactiveExpression, paclet:ref/interpreter/InactiveExpression])  ▪  (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])}})}})