Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Mini HowTo: How to port Perl 5 modules to Perl 6

by iblech (Friar)
on Mar 25, 2005 at 21:29 UTC ( #442414=note: print w/ replies, xml ) Need Help??


in reply to Re: Mini HowTo: How to port Perl 5 modules to Perl 6
in thread Mini HowTo: How to port Perl 5 modules to Perl 6

The old grep/map/sort chain works unmodified, too, I just wanted to demonstrate the new pipeline operators. Actually, there are even some other ways too:

# Perl 5: print join "...", map {...} sort {...} @array; # Perl 6: say (@array.sort:{...} ==> map {...}).join("...");

TIMTOWTDI :)

The accessors are especially useful for subclassing:

class Foo { has $.x; # Explicitly generate an accessor: method x() is rw { return new Proxy: FETCH => {...}, STORE => {...}; } } class Foo::Bar isa Foo { method do_sth { ...; my $var = $.x; # Although used as an variable, the *method* Foo.x is called. # Foo::Bar does *not* directly access the variable. } }

Now, you may ask, "why is that useful?" -- In Perl 5, when one changed the internal representation of some data in the superclass, but fixed the public accessor methods so they translate between the old representation the user expects and the new one used internally, everything was fine. Except, when there was some subclass: The subclass would still directly access the internal representation, which would, of course, not work.

Now, with Perl 6, one may subclass freely without having to fear that internal changes of the superclass will affect the subclass. :)

Generally, the Perl 5 way works in Perl 6, too. But the new ways Perl 6 gives you are often shorter/clearer/more consice/more elegant/more efficient/whatever.

--Ingo


Comment on Re^2: Mini HowTo: How to port Perl 5 modules to Perl 6
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-08-22 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (156 votes), past polls