Runtime evaluation: Difference between revisions

m
(Added Elixir)
m (→‎{{header|Perl 6}}: EVAL not eval)
Line 967:
=={{header|Perl 6}}==
Any syntactically valid sequence of statements may be run, and the snippet to be run can see its outer lexical scope at the point of the <tt>eval</tt>:
<lang perl>myuse ($a, $b) = (MONKEY-5, 7)SEE-NO-EVAL;
 
my $ans = eval 'abs($a * $b)'; # => 35</lang>
my ($a, $b) = (-5, 7);
my $ans = evalEVAL 'abs($a * $b)'; # => 35</lang>
Unlike in Perl 5, <tt>eval</tt> in Perl 6 only compiles and executes the string, but does not trap exceptions. You must say <tt>try eval</tt> to get that behavior (or supply a <tt>CATCH</tt> block within the text to be evaluated).
 
2,392

edits