@Joel, @Craig,

Those are some interesting ideas. My line of thinking isn't oriented around
running dynamically-defined code, so eval usually isn't on my mind. But
that looks like a simple and flexible way of doing it.

@David,

I promise I wasn't complaining! :-)  I found the PDL::Book to be quite
instructive on the use of Inline::PP, but was curious about expanding
outside of Inline. From what I gather, using 'raw' PDL::PP is a bit
cumbersome for small things like what I want to do, so I definitely
understand leaving it out of the book. I shall have a look at the bind
method.

Many thanks again, everyone.

- Tim



On Fri, Mar 9, 2012 at 1:26 PM, <[email protected]> wrote:

> Send Perldl mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Perldl digest..."
>
> Today's Topics:
>
>   1. Re: conditional compilation of inline pp_def (Joel Berger)
>   2. Re: conditional compilation of inline pp_def (Joel Berger)
>   3. Re: conditional compilation of inline pp_def (David Mertens)
>
>
> ---------- Forwarded message ----------
> From: Joel Berger <[email protected]>
> To: Craig DeForest <[email protected]>
> Cc: [email protected], Tim Haines <[email protected]>
> Date: Fri, 9 Mar 2012 12:34:56 -0600
> Subject: Re: [Perldl] conditional compilation of inline pp_def
> Hmm that looks ugly in my email client. Here it is as a gist instead. BTW
> so everyone can follow, yes, those are nested Heredocs.
>
> https://gist.github.com/2007924
>
> Joel
>
> On Fri, Mar 9, 2012 at 12:31 PM, Joel Berger <[email protected]>wrote:
>
>> Good call on the eval. I was having a hard time getting the method to
>> show up correctly from another file. I'm sure its possible, but this was
>> much easier. The warn message is so that you can see that the compiling
>> only happens when the conditional is true.
>>
>> #!/usr/bin/env perl
>>
>> use strict;
>> use warnings;
>>
>> use PDL;
>>
>> my $cond = shift || 0;
>> my $pdl = null();
>>
>> # sometime later
>> if ($cond)
>> {
>>     eval <<'ON_DEMAND_ONLY';
>> warn "Compiling";
>> use Inline Pdlpp => << 'PDLPP';
>>  pp_def('say_hi',
>>     'Pars' => 'a(n)',
>>     'Code' => q{ printf("%s\n", "Hello, world!"); }
>> );
>> PDLPP
>> ON_DEMAND_ONLY
>>     $pdl->say_hi();
>> }
>>
>>
>> On Fri, Mar 9, 2012 at 12:25 PM, Craig DeForest <
>> [email protected]> wrote:
>>
>>> 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
>>>
>>>
>>>
>>
>
>
> ---------- Forwarded message ----------
> From: Joel Berger <[email protected]>
> To: Craig DeForest <[email protected]>
> Cc: [email protected], Tim Haines <[email protected]>
> Date: Fri, 9 Mar 2012 12:45:49 -0600
> Subject: Re: [Perldl] conditional compilation of inline pp_def
> And to finish the mystery, the problem with the external file was that
> Inline has problems with DATA sections outside of the main package. Use the
> string form and it works fine:
>
> -- myscript.pl --
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> use PDL;
>
> my $cond = shift || 0; # can pass a true value as an arg to the script
> my $pdl = null();
>
> # sometime later
> if ($cond)
> {
>     require MyPP;
>     $pdl->say_hi();
> }
>
> -- MyPP.pm --
>
> package MyPP;
>
> use strict;
> use warnings;
>
> use PDL;
> use Inline Pdlpp => <<'PDLPP';
> pp_def('say_hi',
>     'Pars' => 'a(n)',
>     'Code' => q{ printf("%s\n", "Hello, world!"); }
> );
> PDLPP
>
> 1;
>
> Cheers,
> Joel
>
>
>
> On Fri, Mar 9, 2012 at 12:34 PM, Joel Berger <[email protected]>wrote:
>
>> Hmm that looks ugly in my email client. Here it is as a gist instead. BTW
>> so everyone can follow, yes, those are nested Heredocs.
>>
>> https://gist.github.com/2007924
>>
>> Joel
>>
>>
>> On Fri, Mar 9, 2012 at 12:31 PM, Joel Berger <[email protected]>wrote:
>>
>>> Good call on the eval. I was having a hard time getting the method to
>>> show up correctly from another file. I'm sure its possible, but this was
>>> much easier. The warn message is so that you can see that the compiling
>>> only happens when the conditional is true.
>>>
>>> #!/usr/bin/env perl
>>>
>>> use strict;
>>> use warnings;
>>>
>>> use PDL;
>>>
>>> my $cond = shift || 0;
>>> my $pdl = null();
>>>
>>> # sometime later
>>> if ($cond)
>>> {
>>>     eval <<'ON_DEMAND_ONLY';
>>> warn "Compiling";
>>> use Inline Pdlpp => << 'PDLPP';
>>>  pp_def('say_hi',
>>>     'Pars' => 'a(n)',
>>>     'Code' => q{ printf("%s\n", "Hello, world!"); }
>>> );
>>> PDLPP
>>> ON_DEMAND_ONLY
>>>     $pdl->say_hi();
>>> }
>>>
>>>
>>> On Fri, Mar 9, 2012 at 12:25 PM, Craig DeForest <
>>> [email protected]> wrote:
>>>
>>>> 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
>>>>
>>>>
>>>>
>>>
>>
>
>
> ---------- Forwarded message ----------
> From: David Mertens <[email protected]>
> To: Tim Haines <[email protected]>
> Cc: [email protected]
> Date: Fri, 9 Mar 2012 13:18:46 -0600
> Subject: Re: [Perldl] conditional compilation of inline pp_def
> Tim -
>
> I'm sorry that I never go into discussing how to created a stand-alone
> file with PDL::PP code. The normal way to do this is to create a full
> distribution, with ExtUtils::MakeMaker or Module::Build, and use that whole
> framework to build, link, and install the code. If you're writing PDL::PP
> code that you don't plan on using anywhere else, you should use Inline.
>
> As to your specific goal, you're looking for Inline's bind function.
>
> if ($my_condition) {
>     Inline->bind(Pdlpp => q{
>         pp_def('my_func',
>             ....
>         );
>     });
> }
> else {
>     ....
> }
>
> David
>
> 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
>>
>>
>
>
> --
>  "Debugging is twice as hard as writing the code in the first place.
>   Therefore, if you write the code as cleverly as possible, you are,
>   by definition, not smart enough to debug it." -- Brian Kernighan
>
>
> _______________________________________________
> 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