Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Code Generation with Perl?

by tsee (Curate)
on Oct 04, 2003 at 10:09 UTC ( #296488=note: print w/ replies, xml ) Need Help??


in reply to Code Generation with Perl?

My Math::Symbolic module uses code generation to "compile" the function that a Math::Symbolic tree represents to Perl code and/or an anonymous sub. The LaTeX dumper generates LaTeX on the fly, too. For example: (untested)

use Math::Symbolic qw/:all/; my $function = parse_from_string( 'partial_derivative(A*sin(omega*t), t)' ); my ($closure) = $function->apply_derivatives()->to_sub(); print $closure->(5, 3, 1); # A=5, omega=3, t=1 my ($code) = $function->apply_derivatives()->to_code(); print $function->to_latex(replace_default_greek => 1);
Nonetheless, it's usually considered a bad idea to generate code if you can do it someway else. Consider using anonymous subs instead. Steffen


Comment on Re: Code Generation with Perl?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (18)
As of 2014-09-18 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls