Element-wise operations: Difference between revisions

Content added Content deleted
mNo edit summary
m (→‎{{header|Raku}}: more idiomatic, no warnings with latest version)
Line 3,151: Line 3,151:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(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.
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 =
<lang perl6>my @a =
Line 3,159: Line 3,158:


sub msay(@x) {
sub msay(@x) {
say .map( { ($_%1) ?? $_.nude.join('/') !! $_ } ).join(' ') for @x;
for @x -> @row {
print ' ', $_%1 ?? $_.nude.join('/') !! $_ for @row;
say '';
}
say '';
say '';
}
}