Element-wise operations: Difference between revisions

m
→‎{{header|Raku}}: more idiomatic, no warnings with latest version
mNo edit summary
m (→‎{{header|Raku}}: more idiomatic, no warnings with latest version)
Line 3,151:
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2016.05}}
Raku already implements this and other metaoperators as higher-order functions (cross, zip, reduce, triangle, etc.) that are usually accessed through a meta-operator syntactic sugar that is productive over all appropriate operators, including user-defined ones. In this case, a dwimmy element-wise operator (generically known as a "hyper") is indicated by surrounding the operator with double angle quotes. Hypers dwim on the pointy end with cyclic APL semantics as necessary. You can turn the quote the other way to suppress dwimmery on that end. In this case we could have used <tt>»op»</tt> instead of <tt>«op»</tt> since the short side is always on the right.
<lang perl6>my @a =
Line 3,159 ⟶ 3,158:
 
sub msay(@x) {
say .map( { print ' ', ($_%1) ?? $_.nude.join('/') !! $_ } ).join(' ') for @rowx;
for @x -> @row {
print ' ', $_%1 ?? $_.nude.join('/') !! $_ for @row;
say '';
}
say '';
}
2,392

edits