Next | Higher-Order Parsing | 10 |
In Perl:
my $function = eval $code; my $y = $function->($x);
I don't need to explain all the things that can go wrong here, do I?
Even if it could be made safe, it has some problems:
(x^2 + 3*x)* sin(x * 2) + 14
In Perl, ^ means bitwise exclusive or
Not exponentiation
Alternative: implement an evaluator for expressions
Then we can give any notation any meaning we want
Next | Copyright © 2007 M. J. Dominus |