Define a new custom operator in D Language.

Imperatorn johan_forsberg_86 at hotmail.com
Mon Oct 2 18:39:41 UTC 2023


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**.
>
> ![](https://i.imgur.com/UJPAWIW.png)
> 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


More information about the Digitalmars-d-learn mailing list