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 8230 times by 1685 viewers