[VPM] perl 5 and hyper operators on lists

Darren Duncan darren at DarrenDuncan.net
Wed Dec 6 23:30:17 PST 2006


At 3:37 AM -0800 12/6/06, Jer A wrote:
>hi all,
>I am new to hyper operators....I have been studying them in a perl 6 book.
>Does using hyper operators,offer better performance, in manipulating lists,
>than using loops?

Hyper-operators have 2 main purposes, one of which is to allow more 
concise coding (which can reduce bugs), and another is to allow more 
optimizing by the Perl 6 implementation.  When you use a hyper-op, 
you are saying more *what* you want done with an entire list and 
aren't specifying how to do it per se, which means the implementation 
can make some optimizations, including implicit multi-threading.  So 
yes, they should be faster, or at least not slower, and your code is 
simpler anyway.  The reduce-ops are similar in that respect.

>Can I forget about loops altogether?....how complex can I make a hyper
>statment?

A hyper-operator is simply an ordinary operator iterated over a list, 
and that's about how complicated they get, though I think the current 
Perl 6 synopsis show that they may also recurse through 
multidimensional structures in some smart way, which is conceptually 
more complicated.

Have a look at Synopsis 3, 
http://dev.perl.org/perl6/doc/design/syn/S03.html , which is much 
more up to date than any Perl 6 books, about operators; half-way down 
is the hyper-ops section.

>Can Hyper operators be implemented in perl 5?..and will this still offer
>better performance than loops?

They can probably be implemented in Perl 5, but doing it faster will 
undoubtedly require an XS implementation.  That said, the v6.pm 
implementation of Perl 6 over Perl 5 will have to make hyper-ops work 
somehow.

>what other operators can I use to make my programs loopless, and offer
>better performance?

In Perl 6, there are also reduction operators, cross operators, 
junctive operators, which turn some loops into scalar-like 
expressions.  In Perl 5 (and Perl 6), you have "map" and "grep" which 
let you do some loop-like things as an expression rather than a 
statement.

>I am not as concerned about readability of code, just doing things
>efficiently the perl way.

Note, in general, if you want to ask questions about using Perl 6, 
there is a newish "Perl 6 Users" group just for that (List-Subscribe: 
mailto:perl6-users-subscribe at perl.org) ... if you're wanting to just 
apply Perl 6 isms to Perl 5, I'm less sure if that group is suitable.

-- Darren Duncan


More information about the Victoria-pm mailing list