Perl 6 looks quite good

I had a chance to look at the perl 6 advent calendar. What caught my eye was yesterdays post. In it, meta operators are explained.

So here is a common HPC pattern, a reduction operation. Say a sum reduction. Suppose you want to sum up the values in some vector A. In Perl, A would be represented by a list, @a. To get the sum over the elements, you can do this:


$sum = [+] @a;

which means apply the sum operator “+”, between elements of the list.

But of course, we like *AXPY type operations. There, vector C is constant A times vector X plus vector Y. Or in (rough) mathematical notation


C_i = X_i * A + Y_i

So how would we do this in Perl6?


@C = (@X ??*?? $A ) ??+?? @Y;

Some new operators to look into, but this is gonna reduce a code size quite a bit, and make the language more expressive, while making it easier to read. The “?? OP ??” construct makes the thing to the right of it have the same shape as the thing to the left, and the “?? OP ??” does a element by element iteration.

Just look at all those examples they give.

This is nice. Another very good thing about it, is that since Parrot is the VM that Perl (and many others) are being implemented in, there really isn’t any reason why this couldn’t be made to be multicore aware, as well as APU aware.

I had been interested in learning more about Perl6 for a while, but been doing most of my non-C/Fortran work in Perl 5. Looking at this, I think I might be giving Rakudo (Perl 6 implementation) a spin soon. This is looking very good.

Note: for those who want to leave a “but Perl is a write-only language” or “Perl is dead” comment, please don’t waste our time with that … I respect peoples’ choices in using other languages, but if you have to denigrate a different language to justify your choice, then there may be some deeper issues that need to be looked at … a computer language is a tool for expression of an algorithm. Thats it. How easy or how hard it makes your task is up to the language designers.

Viewed 15145 times by 3347 viewers

4 thoughts on “Perl 6 looks quite good

  1. @Rohit

    It is a BLAS operation. My point was that the ability to express these operations naturally and succinctly has been enhanced tremendously. Which allows for simple creation/extension/maintenance of libraries on one hand, and simple expression in terms of code of complex operations.

    You can achieve a similar thing in C++ with explicit operator overloading.

    For this example, you would likely call the BLAS function for vectors of particular length or greater, where the function call overhead is minute as compared to the execution time.

  2. My point was about choices of languages you made. If you like perl, then by all means use it, it’s just that the ” ?? op ?? ” syntax looks downright ugly and kludgy to me.

    If you feel perl works best for you, then sure, use it.

  3. the characters don’t get displayed right:

    @C = @X ??*?? $A ??+?? @Y;

    or ascii equivalents are understood by Perl 6 as well:

    @C = @X >>*>> $A >>+<< @Y;

Comments are closed.