November 18, 2022

On Friday, 18 November 2022 at 18:32:44 UTC, bachmeier wrote:

>
import std;

enum JavaStyleGinormousName { a, b, c, d}

void main() {
    auto var = JavaStyleGinormousName.a;
    writeln(var);
    alias B = JavaStyleGinormousName;
    auto var2 = B.a;
    writeln(var2);
}

This makes everything explicit, with no surprises and no additional learning curve for the new user. This proposal essentially boils down to an implicit

alias $. = [something inferred by the compiler depending on the context

alias $identifier = ExpectedType.identifier;

Your example above would still need the enum type names except you could write:

JavaStyleGinormousName var = $a;

The type name can be omitted for e.g. a function call, but then you can omit the types when passing a function literal to a typed function pointer parameter. Are you against function literal type inference too?

The fact this feature is showing up in other systems languages is evidence it is useful.

November 18, 2022
On 18.11.22 20:54, Adam D Ruppe wrote:
> 
> BTW I used the word `auto` cuz it is a common thing but it could just as well be anything else, it is just a magic temporary alias after all.

_ is pretty commonly used as a placeholder in other languages.
November 18, 2022

On Friday, 18 November 2022 at 21:27:51 UTC, Nick Treleaven wrote:

>

On Friday, 18 November 2022 at 18:32:44 UTC, bachmeier wrote:

>
import std;

enum JavaStyleGinormousName { a, b, c, d}

void main() {
    auto var = JavaStyleGinormousName.a;
    writeln(var);
    alias B = JavaStyleGinormousName;
    auto var2 = B.a;
    writeln(var2);
}

This makes everything explicit, with no surprises and no additional learning curve for the new user. This proposal essentially boils down to an implicit

alias $. = [something inferred by the compiler depending on the context

alias $identifier = ExpectedType.identifier;

Your example above would still need the enum type names except you could write:

JavaStyleGinormousName var = $a;

The type name can be omitted for e.g. a function call, but then you can omit the types when passing a function literal to a typed function pointer parameter. Are you against function literal type inference too?

I'm not following. If I pull out the example from the Case statements example and fix it so it runs, I can do this without any changes to the language, but I'll grant that it requires typing one extra character:

import std.stdio: writeln;

enum WordLetterOfTheDay{ a,b,c,d/*...*/ }
alias w=WordLetterOfTheDay;

void main(){
    auto letterToday = w.b;

    import std.stdio;
    switch(letterToday){
        case w.a:
            writeln("Apple");
            break;
        case w.b:
            writeln("Bicycle");
            break;
        case w.c:
            writeln("Caterpillar");
            break;
        case w.d:
            writeln("Didgeridoo");
            break;
        default:
        	break;
        /*...*/
    }
}

And you can still use the more verbose name if you want. I don't see the benefit from adding extreme levels of complexity to the language. I do see someone checking out the language, seeing this, laughing, and never looking at D again.

>

The fact this feature is showing up in other systems languages is evidence it is useful.

Maybe. They're different languages.

November 18, 2022
On 18.11.22 22:09, Walter Bright wrote:
> What happens in combination with function and template overloading is not discussed.

It does not have to be.

> For example:
> 
>     enum A { a }
>     enum B { a }
> 
>     void ket(A);
>     void ket(B);
> 
>     ...
>     ket(a);
>     ...
> ...

Should be ket($a).

> That's the simplest case. More complex cases come when there are multiple overloaded functions with diverse enum arguments, resulting in an unbounded combinatorial problem of which combination of enum members will be selected.
> ...

This is just not true. Overloading introduces zero additional problems. D already has well-defined overloading rules. You only have to be able to match each function on its own.


> This kind of problem comes up whenever we contemplate adding top-down type inference and try to make it work in combination with the current bottom up method. It works in trivial cases as shown in the DIP, but the complex ones are the problem.

Why "contemplate"? D already has such inference for delegates.

```d
import std.stdio;

enum A{
    a,
    b,
}
enum B{
    b,
    c,
}

void foo(A delegate(A) dg){
    writeln("first overload");
}
void foo(B delegate(B) dg){
    writeln("second overload");
}

void main(){
    foo((x){ // first overload
        static if(__traits(hasMember,typeof(x),"a"))
            return typeof(x).a;
    });
    /+foo((x){ // error, ambiguous
        static if(__traits(hasMember,typeof(x),"b"))
            return typeof(x).b;
    });+/
    foo((x){ // second overload
        static if(__traits(hasMember,typeof(x),"c"))
            return typeof(x).c;
    });
}
```

It works just fine. Now just do literally the same thing for the new enum inference. Probably one can even reuse some of the compiler code.

> (Even worse than the function overloading problem is the template overloading problem, as the compiler will need to instantiate the template with each combination of enum inferences just to figure out what the type of the template is.) 

Again, this has nothing to do with overloading. In any case, just do the same as for the delegate case and reject if there is no explicitly given enum type to pick up on in the function signature. Instantiating all combinations is never what the user expects.
November 18, 2022
On 18.11.22 20:33, H. S. Teoh wrote:
> 
> Here's my proposal: use `.` instead of `$`, and if .identifier is
> ambiguous in any way at all, prohibit ITE and require spelling out the
> enum in full. I.e., prohibit it if there's any ambiguity at all with a
> module name, any global identifier, or it can be a member of multiple
> enums currently in scope.

Well, what if you _wanted_ to access the module-scope variable? I guess there are workarounds, but this still seems a bit messy. Probably still better than using $identifier though.
November 18, 2022

On Friday, 18 November 2022 at 21:12:54 UTC, Walter Bright wrote:

>
with (myObj, Size, Shape, State)

Good idea.

November 18, 2022

On Friday, 18 November 2022 at 19:14:14 UTC, IGotD- wrote:

>

On Friday, 18 November 2022 at 17:54:42 UTC, monkyyy wrote:

> >

using $
If I define opDollar to return an enum; and you define an opIndex to take enums; does it all work?

The $myEnum syntax is really hideous compared to the .myEnum. The .myEnum syntax feels natural where $myEnum looks like it is some kind macro parameter or something. There is a reason that all other example languages like Swift use the . syntax.

Is it possible to use the . syntax but there is a search hierarchy? If there is a global with the same enum name, you must give the full enum name. There might creep in serious bugs, however often you will have some kind of type mismatch.

The $ syntax is so ugly that I don't want this DIP in its current form.

I agree, i also much prefer the .Enum syntax, it's more natural and easier on the eyes

November 19, 2022

On Friday, 18 November 2022 at 15:37:31 UTC, Mike Parker wrote:

>

Discussion Thread

[...]

I think it's not worth adding this to D as well. I have no problem typing out the full name of an enum, and if I or anyone else does face such a difficulty, why not use a short alias?

with(a, b, c, d):

That's a good idea.

November 18, 2022
On 11/18/2022 2:49 PM, Timon Gehr wrote:
> Should be ket($a).

Yah, I missed that. That does change how the lookups work from what I posted.

November 19, 2022
On 19.11.22 02:04, Ki Rill wrote:
> On Friday, 18 November 2022 at 15:37:31 UTC, Mike Parker wrote:
>> ## Discussion Thread
>> [...]
> 
> I think it's not worth adding this to D as well. I have no problem typing out the full name of an enum, and if I or anyone else does face such a difficulty, why not use a short alias?
> 
> ```
> with(a, b, c, d):
> ```
> That's a good idea.

I think this is a little thing that most competing languages have and people are confused that D does not have it.