Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Perl 5, Python, Rakudo, C/C++, Java, Lua?

by raiph (Deacon)
on Mar 12, 2015 at 02:44 UTC ( [id://1119737] : perlmeditation . print w/replies, xml ) Need Help??

(I retitled and moved this content from Re^3: [perl6] Complex Attribute Validation and/or Triggers because I felt it warranted its own post.)

»»» This post is about alpha status Perl 6, not rock solid Perl 5 «««

»ö« . o { "Wouldn't it be fun to mix Rakudo Perl 6 with another lang or three, calling out to each other, passing objects back and forth, subclassing a class defined in another lang, until the whole thing dies a horrible death which you report back to #perl6?" }

  • Inline::Perl5. Stefan Seifert (nine on IRC) wrote the first version of this breakthru module in September last year. It lets one write Perl 5 code in Perl 6; use P5 modules (aiui most of CPAN should work; some exceptions); treat P5 objects as if they were P6 ones; subclass a P5 class in P6; and more. It's suddenly become possible to do stuff like write a Catalyst controller in Perl 6.

  • Inline::Perl6. This new CPAN module is the converse of Inline::Perl5, allowing use of Perl 6 in Perl 5 code by embedding a MoarVM based Rakudo Perl 6 in Perl 5. Also created by Stefan Seifert.

  • Inline::Python for Perl 6. Also recently created by Stefan Seifert. (Note that he's the co-maintainer of Inline::Python for Perl 5.)

  • p6-Inline-C by Tobias Leich (FROGGS on IRC).

  • Inline::Lua for Perl 6. "Both Lua 5.1 and LuaJIT are supported." Started a few weeks ago by raydiak (author of Pray, a ray tracing engine written in Perl 6).

  • The NativeCall interface. Makes it easy for non C hackers to wrap C libs without need for a C compiler or C headers on the target system. (Will become even easier when a C parser in Perl 6 starts parsing headers to automatically construct bindings.) NativeCall is being driven forward by Tobias Leich (FROGGS on IRC). His most recent work is adding support for C++ libs too.

  • Use Java libs in Perl 6 code. Pepe Schwarz (psch on IRC) is leading the Java work.

  • Comment on Perl 5, Python, Rakudo, C/C++, Java, Lua?

Replies are listed 'Best First'.
Re: Perl 5, Python, Rakudo, C/C++, Java, Lua?
by Arunbear (Prior) on Mar 12, 2015 at 10:40 UTC
    Does Inline::Perl5 embed the Perl5 interpreter in the Perl6 one?

      Yes. slides / video (no source code though, at least not on CPAN).

Re: Perl 5, Python, Rakudo, C/C++, Java, Lua?
by Tux (Canon) on Mar 14, 2015 at 10:08 UTC

    Inline::Perl5 now supports passing IO (including deep and dark IO from within XS), so this code works:

    use v6; use Slang::Tuxic; use Inline::Perl5; my $p5 = Inline::Perl5.new; $p5.use ("Text::CSV_XS"); my @rows; my $csv = $p5.invoke ("Text::CSV_XS", "new") or die "Cannot use CSV: ", $p5.invoke ("Text::CSV_XS", "error_diag +"); $csv.binary (1); $csv.auto_diag (1); my $fh = open "/tmp/hello.csv", :r, chomp => False; my Int $sum = 0; while (my $r = $csv.getline ($fh)) { $sum += +$r; } $sum.say;

    To give an example of performance (seconds needed to parse 10000 lines of 5 fields each). Note that Text::CSV::Easy_* only accepts valid CSV and has no options.


    Perl 5

    Text::CSV::Easy_XS0.019
    Text::CSV::Easy_PP0.017
    Text::CSV_XS with bind_columns0.033
    Text::CSV_XS0.038
    Text::CSV_PP0.517
    Pegex::CSV1.350

    Perl 6

    State machine (no options yet)7.027
    Inline::Perl5 + Text::CSV_XS13.082
    Inline::Perl5 + Text::CSV_XS + getline (IO)13.142
    Inline::Perl5 + Text::CSV_PP13.623
    Grammar-based (no options yet)13.210
    Regex based (no options)39.996
    Regex based, all options provided36.075

    When I started in october 2014, the Regex based solution took 260 seconds, so improvement in the language itself is made on a daily basis!


    Enjoy, Have FUN! H.Merijn

      Thanks for the benchmarks! Come back when, or I should rather say, if you succeed to make something that's not several hundred times slower than something that actually works. I doubt you ever will.

      Ada attracted much attention from the programming community as a whole during its early days. Its backers and others predicted that it might become a dominant language for general purpose programming and not just defense-related work. Ichbiah publicly stated that within ten years, only two programming languages would remain, Ada and Lisp. Early Ada compilers struggled to implement the large, complex language, and both compile-time and run-time performance tended to be slow and tools primitive. Compiler vendors expended most of their efforts in passing the massive, language-conformance-testing, government-required "ACVC" validation suite that was required in another novel feature of the Ada language effort.

      You are building another Ada, this time without the backing of DoD and, more importantly, with no chance of a Perl6 mandate.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl 5, Python, Rakudo, C/C++, Java, Lua?
by einhverfr (Friar) on Apr 01, 2015 at 13:29 UTC

    Looks interesting. I am watching some parts of Perl 6 and this could be quite helpful. I am however taken aback by "most of CPAN should work" because I am not sure what would be the obstacles there. Are there specific features that would not work? Like maybe tail calls via goto &subname? Or is this more like "we haven't tested it entirely?

    If Perl 5 modules work flawlessly in Perl 6 including language features unsupported in the latter, then that would give me additional confidence. I actually use tail calls in Perl 5 and that is one of the larger features that if it is not supported would keep me from upgrading, but if I can put it in a Perl 5 module, then no harm done.

        Thanks for the nextwith stuff. I will keep an eye on that.

      You can do tail calls in Perl5 now: 5.4.2 Creating Tail Calls in Higher Order Perl; see also Sub::Call::Tail.

      The CPAN has plenty of “interesting” code that doesn’t work everywhere Perl5 does. It seems likely that a slightly smaller portion would be able work under any kind of harness, Perl6 or otherwise.

        Yes you can. goto &subname also does them. I don't see anything in Perl 6 docs for this functionality however.
Re: Perl 5, Python, Rakudo, C/C++, Java, Lua?
by Jenda (Abbot) on Mar 14, 2015 at 01:03 UTC

    . o { "No, it would not." }

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.