[Edinburgh-pm] Perl code generator

Wim Vanderbauwhede wim.vanderbauwhede at gmail.com
Sun Apr 14 11:11:42 PDT 2013


Hi Murray,

Thanks a lot for the feedback. I apologise for not testing my stuff more
thoroughly, I hadn't actually though people were going to run it, just look
at it :-)


On 13 April 2013 20:36, Murray <perl at minty.org> wrote:

> On Sat, Apr 13, 2013 at 05:36:08PM +0100, Wim Vanderbauwhede wrote:
> > For example:
> >
> > use GPRM;
> > use GPRM::DocFilter;
> >
> > my @dfs = map {new GPRM::DocFilter($_)} 1..8;
> > my $df2 = new GPRM::DocFilter(9);
> >
> >     {
> >         my @vals;
> >         for my $i (1..8) {
> >             push @vals, $dfs[$i-1]->score($i)
> >         }
> >         $df2->aggregate(@vals);
> >     }
>
> Ok -- so I'm not claiming to really grok all of the details, and I've only
> had
> a cursory glance, so forgive stupid / newbie mistakes ... but I always
> find it
> useful to get that feedback, even if it's probably not what you were really
> hoping for here ;)
>
> Also, this is kinda brain dump, sorry :)
>
> ---
>
> So first I forked your repo -- gives me a place to play.
>
> https://github.com/minty/Perl-GPIR-Generator
>
> then
>
>     git clone git at github.com:minty/Perl-GPIR-Generator.git
>
>     cd Perl-GPIR-Generator
>     vi sample
>
> Then I set "sample" to be:
>
>     #!/usr/bin/env perl
>
>     use GPRM;
>     use GPRM::DocFilter;
>
>     my @dfs = map { new GPRM::DocFilter($_) } 1..8;
>     my $df2 = new GPRM::DocFilter(9);
>     my $NTH = 8;
>
>     {
>         my @vals;
>         for my $i (1..$NTH) {
>             push @vals, $dfs[$i-1]->score($i)
>         }
>         $df2->aggregate(@vals);
>     }
>
> ran it, and got:
>
>     § chmod u+x ./sample
>     § ./sample
>
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     ...
>
> I tried it with:
>
>     § perl ./sample
>
> but same result.
>
> I seem to get these littering the filesystem:
>
>     #   _PROC__PROC__PROC__PROC__PROC_sample
>     #   _PROC__PROC__PROC__PROC_sample
>     #   _PROC__PROC__PROC_sample
>     #   _PROC__PROC_sample
>     #   _PROC_sample
>
> Which makes me wonder if File::Temp, used with it's CLEANUP => 1
> constructor
> arg might be relevant?
>
> Could be, will check it out


> I had to Ctrl-C "sample" in both the above cases.
>

This should be fixed now. I made a mistake in how I check for the generated
file name.

>
> fwiw, I'm using perlbrew:
>
>     § perl -v
>     This is perl 5, version 16, subversion 3 (v5.16.3) built for i686-linux
>
>     § cat /etc/lsb-release
>     DISTRIB_ID=Ubuntu
>     DISTRIB_RELEASE=12.04
>     DISTRIB_CODENAME=precise
>     DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
>
> Running:
>
>     § perl transform_GPRM.pl
>
> Seems to work and produce plausible output.
>
>     § perl matmult.pl
>     Can't locate GPRM/MatrixOps.pm in @INC ... [snipped long @INC paths]
>
> I can't see GPRM/MatrixOps.pm in the git repo ... ?
>
I forgot a few lines in the script :-( Fixed now.  GPRM/MatrixOps.pm is a
generated stub, that's why it's not in the repo.


>     § perl matops.pl
>
> produces:
>
> ------------
> ADD TO REG TABLE $GPRM::A
> ------------
> ADD TO REG TABLE $GPRM::B
> ------------
> ADD TO REG TABLE $GPRM::C
> ------------
> ADD TO REG TABLE $GPRM::D
> ------------
> $GPRM::A exists in REG TABLE
> REG_READ <1>:<$GPRM::A>
> ------------
> $GPRM::B exists in REG TABLE
> REG_READ <2>:<$GPRM::B>
> ------------
> ADD TO REG TABLE $GPRM::AB
> ------------
> $GPRM::C exists in REG TABLE
> REG_READ <3>:<$GPRM::C>
> ------------
> $GPRM::D exists in REG TABLE
> REG_READ <4>:<$GPRM::D>
> ------------
> ADD TO REG TABLE $GPRM::CD
> ------------
> $GPRM::AB exists in REG TABLE
> REG_READ <5>:<$GPRM::AB>
> ------------
> $GPRM::CD exists in REG TABLE
> REG_READ <6>:<$GPRM::CD>
> Name "GPRM::CD" used only once: possible typo at _PROC_matops.pl line 85.
> Name "GPRM::C" used only once: possible typo at _PROC_matops.pl line 70.
> Name "GPRM::A" used only once: possible typo at _PROC_matops.pl line 58.
> Name "GPRM::B" used only once: possible typo at _PROC_matops.pl line 58.
> Name "GPRM::D" used only once: possible typo at _PROC_matops.pl line 70.
> Name "GPRM::AB" used only once: possible typo at _PROC_matops.pl line 85.
> Can't locate object method "new" via package "Mat" (perhaps you forgot to
> load "Mat"?) at _PROC_matops.pl line 40.
>
Another mistake in the script, fixed now. You'll still get the warnings,
that is because my transformer is not yet complete.

>
> ---
>
> time for some dinner now -- I'll have a further play with
> transform_GPRM.pl in
> due course, as currently it is the only one that seems to really work for
> me.
>
>
feedback? make it easier to get a working demo, or unit tests.  Test are, in
> addition to all the testing things, my first port of call to run the code
> in
> anger, and start messing with it.  They are often where I copy/paste from
> to
> start playing, as my assumption is they are worked-examples of how the
> code is
> intended to be used.
>
Correct. Only I did not actually test all the test cases in the repo ^_^;

>
> I realise that *might* be tricky in this case ... but ... well, feedback.
>  More
> tests.  Primarily, for a "worked example of the code in use" rather than
> worrying about "comprehensive test coverage".
>
> So ... I tried to create a minimal test file -- no love :(
>
> § cat t/01_basic.t
> #!/usr/bin/env perl
>
> use FindBin;
> use lib "$FindBin::Bin";
>
> use common::sense;
> use Test::More;
>
> use_ok 'GPRM';
>
> done_testing();
>
> murray at testing:~/github/Perl-GPIR-Generator§ perl t/01_basic.t
> Can't open perl script
> "t/_PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC_01_basic.t":
> File name too long
>
Same stupid bug again, should probably be OK now, though I don't know what
the output of this test should be.

>
> ---
>
> fwiw:
>
> #!/usr/bin/env perl
>
> I use perlbrew [1], and this makes yer scripts "more portable" in such
> environs.
>
> Don't know it, will check it out

> use common::sense;
>
Ditto

>
> it works for me, and it's less boilerplate than:
>
>     use strict;
>     use warnings;
>     use 5.10;
>
> plus, I concur with the general sentiment of the pod, even if frankly the
> details are tl;dr for me.  ymmv obviously :)
>
> [1] re: perlbrew ... fwiw, this is my baseline:
>
>     curl -kL http://install.perlbrew.pl | bash
>     echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc
>     source ~/perl5/perlbrew/etc/bashrc
>     perlbrew install --switch stable
>     perlbrew install-cpanm
>
> Optionally, if you have multiple CPUS, with "-j 8" (or some other value
> for 8)
> added to the first "perlbrew install" line.  Makes it silly fast to
> install a
> new Perl :)
>
> http://www.dagolden.com/index.php/1384/parallel-make-for-perlbrew/
>
> Then I rely heavily on cpanm -- at least, for dev/play.  Production is an
> entirely different ball game.
>
How so? cpanm not good for production?

>
>     § cpanm common::sense
>
> etc.
>

Thanks a lot!

Wim


-- 
If it's pointless, what's the point?
If there is a point to it, what's the point?
(Tibor Fischer, "The Thought Gang")


On 13 April 2013 20:36, Murray <perl at minty.org> wrote:

> On Sat, Apr 13, 2013 at 05:36:08PM +0100, Wim Vanderbauwhede wrote:
> > For example:
> >
> > use GPRM;
> > use GPRM::DocFilter;
> >
> > my @dfs = map {new GPRM::DocFilter($_)} 1..8;
> > my $df2 = new GPRM::DocFilter(9);
> >
> >     {
> >         my @vals;
> >         for my $i (1..8) {
> >             push @vals, $dfs[$i-1]->score($i)
> >         }
> >         $df2->aggregate(@vals);
> >     }
>
> Ok -- so I'm not claiming to really grok all of the details, and I've only
> had
> a cursory glance, so forgive stupid / newbie mistakes ... but I always
> find it
> useful to get that feedback, even if it's probably not what you were really
> hoping for here ;)
>
> Also, this is kinda brain dump, sorry :)
>
> ---
>
> So first I forked your repo -- gives me a place to play.
>
> https://github.com/minty/Perl-GPIR-Generator
>
> then
>
>     git clone git at github.com:minty/Perl-GPIR-Generator.git
>
>     cd Perl-GPIR-Generator
>     vi sample
>
> Then I set "sample" to be:
>
>     #!/usr/bin/env perl
>
>     use GPRM;
>     use GPRM::DocFilter;
>
>     my @dfs = map { new GPRM::DocFilter($_) } 1..8;
>     my $df2 = new GPRM::DocFilter(9);
>     my $NTH = 8;
>
>     {
>         my @vals;
>         for my $i (1..$NTH) {
>             push @vals, $dfs[$i-1]->score($i)
>         }
>         $df2->aggregate(@vals);
>     }
>
> ran it, and got:
>
>     § chmod u+x ./sample
>     § ./sample
>
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     Deep recursion on subroutine "PPI::Visitors::visit_tree" at
> PPI/Visitors.pm line 97.
>     ...
>
> I tried it with:
>
>     § perl ./sample
>
> but same result.
>
> I seem to get these littering the filesystem:
>
>     #   _PROC__PROC__PROC__PROC__PROC_sample
>     #   _PROC__PROC__PROC__PROC_sample
>     #   _PROC__PROC__PROC_sample
>     #   _PROC__PROC_sample
>     #   _PROC_sample
>
> Which makes me wonder if File::Temp, used with it's CLEANUP => 1
> constructor
> arg might be relevant?
>
> I had to Ctrl-C "sample" in both the above cases.
>
> fwiw, I'm using perlbrew:
>
>     § perl -v
>     This is perl 5, version 16, subversion 3 (v5.16.3) built for i686-linux
>
>     § cat /etc/lsb-release
>     DISTRIB_ID=Ubuntu
>     DISTRIB_RELEASE=12.04
>     DISTRIB_CODENAME=precise
>     DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
>
> Running:
>
>     § perl transform_GPRM.pl
>
> Seems to work and produce plausible output.
>
>     § perl matmult.pl
>     Can't locate GPRM/MatrixOps.pm in @INC ... [snipped long @INC paths]
>
> I can't see GPRM/MatrixOps.pm in the git repo ... ?
>
>     § perl matops.pl
>
> produces:
>
> ------------
> ADD TO REG TABLE $GPRM::A
> ------------
> ADD TO REG TABLE $GPRM::B
> ------------
> ADD TO REG TABLE $GPRM::C
> ------------
> ADD TO REG TABLE $GPRM::D
> ------------
> $GPRM::A exists in REG TABLE
> REG_READ <1>:<$GPRM::A>
> ------------
> $GPRM::B exists in REG TABLE
> REG_READ <2>:<$GPRM::B>
> ------------
> ADD TO REG TABLE $GPRM::AB
> ------------
> $GPRM::C exists in REG TABLE
> REG_READ <3>:<$GPRM::C>
> ------------
> $GPRM::D exists in REG TABLE
> REG_READ <4>:<$GPRM::D>
> ------------
> ADD TO REG TABLE $GPRM::CD
> ------------
> $GPRM::AB exists in REG TABLE
> REG_READ <5>:<$GPRM::AB>
> ------------
> $GPRM::CD exists in REG TABLE
> REG_READ <6>:<$GPRM::CD>
> Name "GPRM::CD" used only once: possible typo at _PROC_matops.pl line 85.
> Name "GPRM::C" used only once: possible typo at _PROC_matops.pl line 70.
> Name "GPRM::A" used only once: possible typo at _PROC_matops.pl line 58.
> Name "GPRM::B" used only once: possible typo at _PROC_matops.pl line 58.
> Name "GPRM::D" used only once: possible typo at _PROC_matops.pl line 70.
> Name "GPRM::AB" used only once: possible typo at _PROC_matops.pl line 85.
> Can't locate object method "new" via package "Mat" (perhaps you forgot to
> load "Mat"?) at _PROC_matops.pl line 40.
>
> ---
>
> time for some dinner now -- I'll have a further play with
> transform_GPRM.pl in
> due course, as currently it is the only one that seems to really work for
> me.
>
> feedback? make it easier to get a working demo, or unit tests.  Test are,
> in
> addition to all the testing things, my first port of call to run the code
> in
> anger, and start messing with it.  They are often where I copy/paste from
> to
> start playing, as my assumption is they are worked-examples of how the
> code is
> intended to be used.
>
> I realise that *might* be tricky in this case ... but ... well, feedback.
>  More
> tests.  Primarily, for a "worked example of the code in use" rather than
> worrying about "comprehensive test coverage".
>
> So ... I tried to create a minimal test file -- no love :(
>
> § cat t/01_basic.t
> #!/usr/bin/env perl
>
> use FindBin;
> use lib "$FindBin::Bin";
>
> use common::sense;
> use Test::More;
>
> use_ok 'GPRM';
>
> done_testing();
>
> murray at testing:~/github/Perl-GPIR-Generator§ perl t/01_basic.t
> Can't open perl script
> "t/_PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC__PROC_01_basic.t":
> File name too long
>
> ---
>
> fwiw:
>
> #!/usr/bin/env perl
>
> I use perlbrew [1], and this makes yer scripts "more portable" in such
> environs.
>
> use common::sense;
>
> it works for me, and it's less boilerplate than:
>
>     use strict;
>     use warnings;
>     use 5.10;
>
> plus, I concur with the general sentiment of the pod, even if frankly the
> details are tl;dr for me.  ymmv obviously :)
>
> [1] re: perlbrew ... fwiw, this is my baseline:
>
>     curl -kL http://install.perlbrew.pl | bash
>     echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc
>     source ~/perl5/perlbrew/etc/bashrc
>     perlbrew install --switch stable
>     perlbrew install-cpanm
>
> Optionally, if you have multiple CPUS, with "-j 8" (or some other value
> for 8)
> added to the first "perlbrew install" line.  Makes it silly fast to
> install a
> new Perl :)
>
> http://www.dagolden.com/index.php/1384/parallel-make-for-perlbrew/
>
> Then I rely heavily on cpanm -- at least, for dev/play.  Production is an
> entirely different ball game.
>
>     § cpanm common::sense
>
> etc.
>



-- 
If it's pointless, what's the point?
If there is a point to it, what's the point?
(Tibor Fischer, "The Thought Gang")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/edinburgh-pm/attachments/20130414/d8e5a863/attachment-0001.html>


More information about the Edinburgh-pm mailing list