Runtime evaluation/In an environment: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 203:
😖️ error: #|user| : unbound variable : x
</lang>
 
=={{header|Elena}}==
Using ELENA Script engine (3.3.0):
Line 332 ⟶ 333:
(dict)
print .x # fails</lang>
 
=={{header|Go}}==
<lang go>package main
Line 748 ⟶ 750:
print eval_with_x('3 * $x', 5, 10), "\n"; # Prints "15".</lang>
 
=={{header|Perl 6}}==
{{Works with|rakudo|2015-12-22}}
For security, you must explicitly allow use of 'EVAL'.
<lang perl6>use MONKEY-SEE-NO-EVAL;
sub eval_with_x($code, *@x) { [R-] @x.map: -> \x { EVAL $code } }
 
say eval_with_x('3 * x', 5, 10); # Says "15".
say eval_with_x('3 * x', 5, 10, 50); # Says "105".</lang>
 
=={{header|PHP}}==
Line 874 ⟶ 867:
(- (with b) (with a)))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2015-12-22}}
For security, you must explicitly allow use of 'EVAL'.
<lang perl6>use MONKEY-SEE-NO-EVAL;
sub eval_with_x($code, *@x) { [R-] @x.map: -> \x { EVAL $code } }
 
say eval_with_x('3 * x', 5, 10); # Says "15".
say eval_with_x('3 * x', 5, 10, 50); # Says "105".</lang>
 
=={{header|REBOL}}==
Line 943 ⟶ 946:
 
}</lang>
 
=={{header|Scheme}}==
Almost identical to the [[Common Lisp]] version above.
Line 958 ⟶ 962:
 
say eval_with_x(x: 3, y: 5, code: '2 ** x'); # => 24</lang>
 
=={{header|Simula}}==
<lang simula>BEGIN
Line 1,280 ⟶ 1,285:
 
eval_with {expr {2**$x}} 3 5 ;# ==> 24</lang>
 
=={{header|TI-89 BASIC}}==
 
<lang ti89b>evalx(prog, a, b)
Func
Local x,eresult1,eresult2
a→x
expr(prog)→eresult1
b→x
expr(prog)→eresult2
Return eresult2-eresult1
EndFunc
 
■ evalx("ℯ^x", 0., 1)
1.71828</lang>
 
There are no facilities for control over the environment; expr() evaluates in the same environment as the caller, including local variables. [Someone please verify this statement.] [[Category:TI-89 BASIC examples needing attention]]
 
=={{header|TXR}}==
Line 1,332 ⟶ 1,354:
 
(eval-subtract-for-two-values-of-x '(exp x) 1 2)</lang>
 
=={{header|TI-89 BASIC}}==
 
<lang ti89b>evalx(prog, a, b)
Func
Local x,eresult1,eresult2
a→x
expr(prog)→eresult1
b→x
expr(prog)→eresult2
Return eresult2-eresult1
EndFunc
 
■ evalx("ℯ^x", 0., 1)
1.71828</lang>
 
There are no facilities for control over the environment; expr() evaluates in the same environment as the caller, including local variables. [Someone please verify this statement.] [[Category:TI-89 BASIC examples needing attention]]
 
=={{header|UNIX Shell}}==
10,327

edits