PDL::NiceSlice is very convenient in that it allows a more
natural array-style pdl element and slice addressing
syntax. The downside is that it's use of a perl source
filter makes "NiceSlice Perl" not valid Perl.
This can cause problems in two ways: (1) the NiceSlice
filter might modify a detect a plain perl construct as a
slicing one and filter the code instead of allowing it to
pass, and (2) perl runtime environments might not support
the use of source filters as indicated in the following
report below to the perldl mailing list.
For portability and robustness of PDL, it is needed
that the PDL core modules be as much portable perl
as possible. One possibility would be to remove
NiceSlice constructs from the PDL core sources in
preference for the ->slice() ones. That can be done
in the near term.
In the longer term, I propose that we add a
build-time NiceSlice processing step to the PDL
install process. The result of this would be the
same module files as currently, just that the
PDL::NiceSlice constructs would already be
source-filtered leaving "pure perl" only for the
blib/ install files.
On 9/23/2010 9:00 AM, Sacha Fouchard wrote:
> Hello everybody,
> This is my problem that could be interesting for many of you.
>
> When I try to use PDL in a prog source and create an executable with
> Activestate perlapp, I 've got the following error after compilation, at
> run time (The exe is correctly created).
>
> When I launch the prog, it says:
>
> syntax error at /<C:\prog.exe>PDL/MatrixOps.pm line 444, near "0:"
> syntax error at /<C:\prog.exe>PDL/MatrixOps.pm line 449, near "1:"
> syntax error at /<C:\prog.exe>PDL/MatrixOps.pm line 450, near "0:"
> syntax error at /<C:\prog.exe>PDL/MatrixOps.pm line 827, near "2:"
>
> For example, line 443 in MatrixOps.pm is :
> determinant( $a->(0:$i-1,1:-1)->append( $a->($i+1:-1,1:-1 ) ) );
> The pb seems to come from niceslicing syntax.
>
> But, if I run the prog directly under the shell, it works perfectly.
>
> What's happening?
>
> Try a prog with nothing but only "use PDL", compile it run, and see.
> I found 12 lines with problems in MatrixOps.pm.
>
> I use perl 5.10 x86 and the lastest PDL from CPAN (2.4.7) on win 7 x64.
> The problem was the same under vista 32 with perl 5.10 and PDL 2.4.6.
>
> Thank you all,
> Sacha
A quick review of the .pm files in the PDL build that 'use PDL::NIceSlice'
results as follows:
PDL/AutoLoader.pm # has line to use for prefiltering
PDL/IO/Dumper.pm # commented out use PDL::NiceSlice
PDL/NiceSlice.pm # duh!
PDL/Graphics/PGPLOT/Window.pm # uses PDL::NiceSlice
PDL/Graphics2D.pm # uses PDL::NiceSlice
PDL/IO/FITS.pm # uses PDL::NiceSlice
PDL/MatrixOps.pm # uses PDL::NiceSlice
PDL/Perldl2/Plugin/NiceSlice.pm # uses PDL::NiceSlice
PDL/Transform.pm # uses PDL::NiceSlice
PDL/Transform/Cartography.pm # uses PDL::NiceSlice
PDL/Transform/Proj4.pm # uses PDL::NiceSlice
And I notice that the PDL::AutoLoader module has a line in it
for the import routine that is pretty much the desired pre-filter
form of PDL::NiceSlice. All that needs to be done is wrap it
up in a script that can be used manually or part of the PDL build
and install process.
perldlpp pre-processor script
I've attached a simple perldlpp pre-processor script to this
ticket based on the code in PDL/AutoLoader.pm. It can
be used to filter out the NiceSlice calls in a PDL install
(the files listed in the previous comment) so that the source
filter is not needed. That should enable a perlapp to be
built. Good luck. I've added the code to this comment so
folks can cut and paste from their browser if desired.
--Chris
#!/usr/bin/perl
#
use PDL::NiceSlice;
my $prefile = "";
{
local $/;
$prefile = <>;
}
my ($postfile) = &PDL::NiceSlice::perldlpp("PDL::NiceSlice", $prefile);
print $postfile;
The perldlpp.pl script takes as command line argument(s)
the file to filter for PDL::NiceSlice constructs. It outputs the
result to STDOUT:
On unixen:
perldlpp.pl file-w-niceslice.pm > clean-file.pm
Or on win32:
perl perldlpp.pl file-w-niceslice.pm > clean-file.pm
I've added perldlpp.pl to the utils/ directory of the PDL git
and it should be available there in the next CPAN release.
The script is not installed anywhere during a build but it
is there if you wish to use it.
I recently looked at the perl .pmc file format
which hsa been reinvigorated for perl6 to perl5
translation via Module::Compile. A natural
location for the pre-converted NiceSlice code
would be in the corresponding .pmc file.
Conveniently, Module::Compile already
handles the problem of skipping POD lines
during the source filtering.
Follow up on related PDL::NiceSlice work. Experimental refactoring
of PDL::NiceSlice to use Filter::Simple appears very promising.
Unfortunately, it does not appear that Module::Compile is compatible
with Filter::Simple. In order to proceed with this approach, the two
modules will need to be reconciled somehow.
I anticipate that the PDL::NiceSlice filter re-work will enable this functionality as well. Bumping priority to match.