First Draft: Member of Operator
Salih Dincer
salihdb at hotmail.com
Thu Sep 12 18:39:54 UTC 2024
On Wednesday, 11 September 2024 at 11:08:18 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> The member of operator is a unified method for acquiring a
> member
> of a context.
>
> It rewrites into ``context.Identifier`` from ``:Identifier``.
It's used very common this sign (colon ```:```) wouldn't cause
confusion or pending trouble? In fact The symbol in draft
resembles the assignment operator in J language. The : symbol is
used in both switches (to the right of the ```case```) and enums.
The ```: symbol``` in enums is typically used to specify the
underlying data type of the enum. This determines the data type
in which the enum constants will be stored. For example, you can
have an enum based on int, byte, short, or string.
For instance in D, we can use the ```: symbol``` when defining an
enum like this:
```d
enum Days : byte
{
Sunday = 1 , Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday
}
```
In this case, using enums on the left and right means mental
confusion. Similarly, in cases, on the right and left at the same
time...
**Last question:** Can we get rid of the parentheses like in the
example below? Just like when using ```with(E)```
```d
T mul(uint e = 1, T)(T value) if (e < 3)
{
static if (e == E.Positive)
{
return 1 * value;
}
else static if (e == E.Superposition)
{
return 2 * value;
}
return 0;
}
enum E
{
Negative, Positive, Superposition
}
import std.stdio;
void main()
{
4.mul!(E.Positive).writeln;
//4.mul!:Positive.writeln;
with (E) 4.mul!Superposition.writeln;
4.mul!2.writeln;
}
```
SDB at 79
More information about the dip.development
mailing list