Am I evil for this?

rassoc rassoc at posteo.de
Sat Oct 15 01:11:02 UTC 2022


On 10/15/22 00:44, Walter Bright via Digitalmars-d wrote:
> I've thought about it many times. It keeps coming back to "it's just too ugly."
> 
> Operator precedence is also a problem.

Raku (formerly Perl 6) is very interesting in that regard. They not only allow you to define custom operators, but also specify their precedence and associativity right in the function signature.

sub prefix:<Σ>(...)
sub infix:<!!>(...) is tighter(&infix:<+>)
sub infix:<§>(...) is assoc<right>
sub circumfix:<[ ]>(...)

And they go even further and allow you to combine these to form meta operators.

> my @a = 1, 2, 3
> @a Z @a    # zip infix operator
   ((1 1) (2 2) (3 3))
> @a Z+ @a
   (2 4 6)    # zip combined with +

If only the language wasn't dog slow. :)


More information about the Digitalmars-d mailing list