Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 scrutinizing the Monastery: (5)
As of 2015-07-04 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls