Am I evil for this?
solidstate1991
laszloszeremi at outlook.com
Sun Oct 16 20:05:22 UTC 2022
On Saturday, 15 October 2022 at 01:11:02 UTC, rassoc wrote:
> 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. :)
At least Σ is perfectly doable in D thanks to its unicode support
(if I remember correctly)
```d
public double Σ(...) {
//code goes here
}
```
Languages with custom operators will compile slow and will run
even slower if they're scripting languages. My alternative for D
would be just expand upon the currently existing number of
operators with unicode characters, but also give them some
alternative way to access them (e.g. having both an `⋃` operator
and an `__opUnion` substitute), so people won't get a heart
attack if they don't know how to get them on their keyboards.
More information about the Digitalmars-d
mailing list