Runtime evaluation: Difference between revisions
m
→{{header|Perl 6}}: EVAL not eval
(Added Elixir) |
SqrtNegInf (talk | contribs) 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>
my $ans = eval 'abs($a * $b)'; # => 35</lang>▼
my ($a, $b) = (-5, 7);
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).
|