Define a new custom operator in D Language.
BoQsc
vaidas.boqsc at gmail.com
Mon Oct 2 19:28:32 UTC 2023
On Monday, 2 October 2023 at 18:39:41 UTC, Imperatorn wrote:
> On Monday, 2 October 2023 at 18:34:13 UTC, BoQsc wrote:
>> Here is my issue: I've found a formula on Wikipedia.
>>
>> It's called **Hashing by division**.
>>
>> 
>> As you can see it uses **mod** keyword to achieve the modulus
>> operation.
>>
>> In D language we use modulus operator `%` and it might look
>> more like this:
>> ```
>> h(x) M % m
>> ```
>>
>> This clearly introduces confusion between the source
>> (wikipedia) and the implementation (dlang version).
>>
>> I would like to know how we could define/alia ourselves a
>> `mod` operator in D Language.
>>
>> ```
>> h(x) M mod m
>> ```
>>
>> ---
>> **This might lead to less gaps between math formulas and the
>> implementation.**
>>
>> Or at the very least would allow to define a formula in the
>> source code for further implementation and introduce some
>> consistency.
>
> https://dlang.org/spec/operatoroverloading.html#binary
Overloading seems to only overload behaviour of existing
operator, like:
```
+ - * / % ^^ &
| ^ << >> >>> ~ in
```
I'm unable to see how the operator overloading would allow to
define a new custom operator.
More information about the Digitalmars-d-learn
mailing list