http://www.perlmonks.org?node_id=1041130


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

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.