Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Perl 6 <-> Perl 5 bridges (was Re^2: Capturing parenthesis and grouping square brackets)

by Jenda (Abbot)
on Jun 20, 2013 at 23:43 UTC ( [id://1040042]=note: print w/replies, xml ) Need Help??


in reply to Perl 6 <-> Perl 5 bridges (was Re^2: Capturing parenthesis and grouping square brackets)
in thread Capturing parenthesis and grouping square brackets

"Perl 6 match objects"? OK, not that I think Perl6 actually matters, but still ... having experience with the insanely overcomplicated Match/Matches/etc./etc./etc./etc. objects of the .Net regular expressions ... this sounds scary. So I asked uncle Google, ended up in per6-regex-intro and ... I did not like what I saw. OK. So the matches are in the object named $/ (OK, so $/ meant something in Perl5, let's change that!) and you can access them as $/[0], $/[1], ... (hey, wasn't we supposed to use @ for arrays. Oh, right, this is an object, you just index it as if it was an array, but ...) ... and there are shortcuts in the form $0, $1, $2, ...

WHAT?!? Yeah, the sortcuts start with $0! Yeah, what used to be $1 is now $0, what used to be $2 is now $1 etc. Just lovely! Imagine you got yourself into the situation when you have to write Perl6 code while still maintaining Perl5 code. I'd love to have a penny for every full hour lost because of the confusion caused by this change! Even with the number of people using Perl6 now, I'm sure it'd pay a few beers.

The more I know about Perl6, the more I hope it's gonna disappear almost without a trace as a failed experiment. It uses the name, it looks deceptively similar, yet it is full of changes carefuly designed to cause as much confusion as possible.

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

Replies are listed 'Best First'.
Re^2: Perl 6 <-> Perl 5 bridges (was Re^2: Capturing parenthesis and grouping square brackets)
by raiph (Deacon) on Jun 21, 2013 at 08:32 UTC
    Perl 6 is many things. For one, it includes a language I'll call STD. STD is specifically designed to host other languages including ones I'll call Pure Perl 5 (a new Perl 5 parser) and #p5p perl (Pumpkin Perl). In your comment you explore STD but then reject everything, which means you've thrown the babies (Pure Perl 5 and #p5p perl hosted alongside Pure Perl 5) out with the bathwater.

    Maybe you can reconsider the bathtub so you can at least look forward to using Pure Perl 5 (which supports $/ as input record separator, $0 as the executable name, and so on) running on android or in a browser and supporting parallel processing and so on.

    So the matches are in the object named $/ (OK, so $/ meant something in Perl5, let's change that!)

    If you want $/ as the input separator, use a Perl 5.

    I agree with @Larry (the team who designed the Perl 6 STD language) that constraining the Perl 6 STD language to back compat with Perl 5 syntax and semantics would have been a big mistake and a big missed opportunity. The end result is still much more friendly to the average Perl 5 user than, say, lisp, haskell, or scala.

    you can access them as $/[0], $/1, ... (hey, wasn't we supposed to use @ for arrays. Oh, right, this is an object, you just index it as if it was an array, but ...)

    You can use @ for arrays in the STD language of Perl 6, but you don't have to:

    my $array; $array[3] = True; my @array; @array[3] = True;

    ... and there are shortcuts in the form $0, $1, $2, ... WHAT?!? Yeah, the sortcuts start with $0!

    I agree this sounds particularly disturbing. In practice it doesn't trip folk up. Note that you can do this:

    say "bar" ~~ /$1=(\w)(\w)(\w)/; say $2; # a

    The more I know about Perl6, the more I hope it's gonna disappear almost without a trace as a failed experiment.

    The community is sustainable, vibrant, and growing. The contributor base, family of languages, Rakudo compiler, Rakudo debugger, toolchain, modules, doc, and intrastructure are all maturing nicely. The team has figured out the path to speeding Rakudo up by orders of magnitude. Larry's writing a Camel equivalent. There's still $100k left of the Hague grant. Sorry, but it ain't going away. :)

    Perl 6 is already attracting curious hackers that have never touched Perl 5 and will I predict begin to attract Perl 5 users next year that want to be able to write in a Perl (5ish or 6ish) on new platforms (eg android via the jvm or browsers via javascript), and/or use new capabilities (eg automatic parallelizing) and/or gain expressivity (grammars, lispish macros, etc.). You are free to ignore it but I'm confident it is here to stay and is inevitably going to help usefully address many of the long standing problems Perl 5 has.

      It's one thing to not constrain Perl6 to back compat and another to create unnecessary confusion by arbitrary operator and sigil changes. No the result is not more friendly, the result is more confusing. It's like Russian to a Czech. Yeah the languages have lots of similarities, part of the vocabulary, the declination system ... which means that Czechs use Slovak words with Russian accents in cases where the Russian word is completely different, they use word that sound similar, but mean something completely different, waste time trying to remember a word when pronouncing the Czech one in Russian accent would be correct, they decline all wrong, because while the declinations are deceptively similar they are also different etc. etc. etc.

      All this doesn't matter that much when speaking to a human being (unless that being is a teacher), communication with a compiler is much less forgiving and when combined with your hailed two kindaPerl5s this just creates an insane mess.

      You can use @ for arrays in the STD language of Perl 6, but you don't have to

      So what's the difference between $array and @array then? Sigils are a perfect example of an absolutely pointless and confusion generating change. Imagine you are new to all this and you ask uncle Google what the heck do those $s and @s and %s mean ... you get contradicting answers!

      The toolchain eventually created by this project may end up being used for something, but so far it has hurt rather then helped Perl.

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

        So what's the difference between $array and @array then?

        $ indicates that a variable will behave as if its content were a singular thing. That singular thing could be a number, string, routine, object, etc. -- or an array or hash. In list context its content will evaluate to be a singular thing; if it's actually plural, that singular thing will be a reference to the plural thing.

        @ indicates that a variable will behave as if its content were a plural thing. If the content is actually singular it behaves like a 1 element array.

        No the result is not more friendly

        Perhaps you did not understand that my "more friendly" comment was about P5ers learning P6 versus learning lisp, haskell or scala. Or perhaps I just need to be more concrete.

        Consider a dissatisfied or adventurous P5er who is considering learning lisp or haskell to better solve a problem or advance their skills or career. To facilitate comparison, here's a simple example task, the Same Fringe task on Rosettacode:

        Write a routine that will compare the leaves ("fringe") of two binary trees to determine whether they are the same list of leaves when visited left-to-right ... an elegant solution is one that can perform the minimum amount of work to falsify the equivalence of the fringes when they differ somewhere in the middle, short-circuiting the unnecessary additional traversals and comparisons.

        Rosettacode solutions in lisp (racket), haskell, and Perl 6:

        === lisp (racket) === #lang racket (require racket/control) (define (make-fringe-getter tree) (&#955; () (let loop ([tree tree]) (match tree [(cons a d) (loop a) (loop d)] ['() (void)] [else (fcontrol tree)])) (fcontrol 'done))) (define (same-fringe? tree1 tree2) (let loop ([get-fringe1 (make-fringe-getter tree1)] [get-fringe2 (make-fringe-getter tree2)]) (% (get-fringe1) (&#955; (fringe1 get-fringe1) (% (get-fringe2) (&#955; (fringe2 get-fringe2) (and (equal? fringe1 fringe2) (or (eq? fringe1 'done) (loop get-fringe1 get-fringe2))))))))) === haskell === data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Show, Eq) fringe :: Tree a -> [a] fringe (Leaf x) = [x] fringe (Node n1 n2) = fringe n1 ++ fringe n2 sameFringe :: (Eq a) => Tree a -> Tree a -> Bool sameFringe t1 t2 = fringe t1 == fringe t2 === Perl 6 === sub fringe ($tree) { multi sub fringey (Pair $node) { fringey $_ for $node.kv; } multi sub fringey ( Any $leaf) { take $leaf; } (gather fringey $tree), Cool; } sub samefringe ($a, $b) { all fringe($a) Z=== fringe($b) }

        The P6 solution invisibly incorporates lazy processing (stolen from haskell) and parallel processing (the all "junction") and visibly incorporates multi subs (stolen from lisp).

        Of the three solutions, I think the P6 one will look by far the most approachable and be by far the easiest to explain to an average P5er.


        The P6 design takes in to account bridging to P5 in many more ways than just providing more syntactic and semantic continuity than most non-Perl langs (imo). For example, it supports inline mixing of langs (and does so with way more underlying cleanliness and power than P5's equivalents):

        use v5; # start with p5 code if ( $^O eq 'MSWin32' ) { # more p5 code } elsif ( $^O eq 'Android' ) { use 6.0.0; # switch to p6 code say "On $*OS"; # $*OS is p6 equivalent to $^O multi sub foo(*@args) { ... } } say "Back to Perl 5 on $^O"

        I agree that there are heavy downsides to mixing langs like this. I don't agree that those downsides are so great that it never makes sense to mix langs inline, even ones that are closely related. YMMV.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1040042]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-29 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found