Matrix multiplication: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
m (→‎{{header|Raku}}: Fix comments: Perl 6 --> Raku)
Line 3,777: Line 3,777:
{{works with|Rakudo|2015-09-22}}
{{works with|Rakudo|2015-09-22}}


There are three ways in which this example differs significantly from the original Perl 5 code. These are not esoteric differences; all three of these features typically find heavy use in Perl 6.
There are three ways in which this example differs significantly from the original Perl 5 code. These are not esoteric differences; all three of these features typically find heavy use in Raku.


First, we can use a real signature that can bind two arrays as arguments, because the default in Perl 6 is not to flatten arguments unless the signature specifically requests it.
First, we can use a real signature that can bind two arrays as arguments, because the default in Raku is not to flatten arguments unless the signature specifically requests it.
We don't need to pass the arrays with backslashes because the binding choice is made lazily
We don't need to pass the arrays with backslashes because the binding choice is made lazily
by the signature itself at run time; in Perl 5 this choice must be made at compile time.
by the signature itself at run time; in Perl 5 this choice must be made at compile time.
Line 3,785: Line 3,785:


Second, we use the X cross operator in conjunction with a two-parameter closure to avoid writing
Second, we use the X cross operator in conjunction with a two-parameter closure to avoid writing
nested loops. The X cross operator, along with Z, the zip operator, is a member of a class of operators that expect lists on both sides, so we call them "list infix" operators. We tend to define these operators using capital letters so that they stand out visually from the lists on both sides. The cross operator makes every possible combination of the one value from the first list followed by one value from the second. The right side varies most rapidly, just like an inner loop. (The X and Z operators may both also be used as meta-operators, Xop or Zop, distributing some other operator "op" over their generated list. All metaoperators in Perl 6 may be applied to user-defined operators as well.)
nested loops. The X cross operator, along with Z, the zip operator, is a member of a class of operators that expect lists on both sides, so we call them "list infix" operators. We tend to define these operators using capital letters so that they stand out visually from the lists on both sides. The cross operator makes every possible combination of the one value from the first list followed by one value from the second. The right side varies most rapidly, just like an inner loop. (The X and Z operators may both also be used as meta-operators, Xop or Zop, distributing some other operator "op" over their generated list. All metaoperators in Raku may be applied to user-defined operators as well.)


Third is the use of prefix <tt>^</tt> to generate a list of numbers in a range. Here it is
Third is the use of prefix <tt>^</tt> to generate a list of numbers in a range. Here it is