Yes. That, or put the whole thing in a non-substituting quote block and eval 
that block at run-time.


On Mar 9, 2012, at 11:23 AM, Joel Berger wrote:

> IIRC all Inline mechanisms work essentially at compile time. However, if you 
> wanted to delay it, you might put your Inline code in another file, then 
> `require` that file if needed. I believe this should behave as you would like.
> 
> # file: MyPP.pm
> use PDL;
> use Inline qw(Pdlpp);
> 
> __END__
> __Pdlpp__
> pp_def('say_hi',
>     'Pars' => 'a(n)',
>     'Code' => q{ printf("%s\n", "Hello, world!"); }
> );
> 
> # file: myscript.pl
> use PDL;
> 
> my $cond = 0;
> my $pdl = null();
> 
> # sometime later
> if ($cond)
> {
>     require MyPP;
>     $pdl->say_hi();
> }
> 
> Admittedly I haven't tried this code, and I'm not as familiar with PDL::PP as 
> I am with XS-y things, but IMO this kind of a mechanism should work.
> 
> Joel
> 
> On Fri, Mar 9, 2012 at 11:47 AM, Tim Haines <[email protected]> 
> wrote:
> Greetings, all.
> 
> I just read through the sections of PDL::Book and PDL::Tutorial that cover 
> PP, but I didn't see an example of conditional compilation of a pp_def. Is 
> this even possible using PP::Inline given the way the __END__ and __Pdlpp__ 
> macros work? Is there a way to do this just using PDL::PP? I am uncertain how 
> to use 'raw' PDL::PP since the examples from PDL::Book and PDL::Tutorial all 
> use PDL::PP::Inline (unless I missed it!).
> 
> [code]
> 
> use PDL;
> use Inline qw(Pdlpp);
> my $cond = 0;
> my $pdl = null();
> 
> # sometime later
> if ($cond)
> {
>     $pdl->say_hi();
> }
> 
> # at the end of the script
> if ($cond)      # Perl generates an error here since it can't see the closing 
> brace
> {
> __END__
> __Pdlpp__
> pp_def('say_hi',
>     'Pars' => 'a(n)',
>     'Code' => q{ printf("%s\n", "Hello, world!"); }
> );
> }   <--- The Perl parser can't see this brace, and PP generates an error for 
> unclosed brace.
> 
> [/code]
> 
> The principle reason I am looking for this functionality is to remove the 
> overhead of generating/compiling/linking the xs definition of say_hi unless 
> the function is actually needed at runtime.
> 
> Many thanks.
> 
> - Tim
> 
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
> 
> 
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to