November 20, 2022

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

>

Discussion Thread

This is the discussion thread for the first round of Community Review of DIP 1044, "Enum Type Inference":

https://github.com/dlang/DIPs/blob/e2ca557ab9d3e60305a37da0d5b58299e0a9de0e/DIPs/DIP1044.md

The review period will end at 11:59 PM ET on December 3, or when I make a post declaring it complete. Discussion in this thread may continue beyond that point.

Here in the discussion thread, you are free to discuss anything and everything related to the DIP. Express your support or opposition, debate alternatives, argue the merits, etc.

However, if you have any specific feedback on how to improve the proposal itself, then please post it in the Feedback Thread. The Feedback Thread will be the source for the review summary that I will write at the end of this review round. I will post a link to that thread immediately following this post. Just be sure to read and understand the Reviewer Guidelines before posting there:

https://github.com/dlang/DIPs/blob/master/docs/guidelines-reviewers.md

And my blog post on the difference between the Discussion and Feedback threads:

https://dlang.org/blog/2020/01/26/dip-reviews-discussion-vs-feedback/

Please stay on topic here. I will delete posts that are completely off-topic.

I have very simple feedback.

STOP CHANGING THE GOD DAMN SYNTAX!
STOP, STOP, STOP, and if you still have some doubt, STOP!

Every time, it breaks a ton of tools.

It's not worth it.

If typing the name of the enum is too long, then just use with or alias E = MyEnumNameThatIsTooLongAndAnoyingToType;.

These changes do not solve any actual problem. They just break tools.

STOP IT!

November 20, 2022

On Saturday, 19 November 2022 at 08:49:31 UTC, Walter Bright wrote:

>

Advantages of this scheme:

  1. doesn't need the special $ which people don't seem to like, and using . conflicts with existing use

  2. makes use of the already present with semantics

  3. seems to have a natural feel to it

Can I open one or more 'enum' namespaces for a function, because sometimes, enum values are continuous,and you do not need 'switch' statements. At this time, I still want to omit 'enum' names' to use the values.

Similarly, can we also open the 'namespace' of one or more classes or structs for a function.
In this way, just like a 'free functions', you can directly use the 'static' function in the 'class/struct'.

How about this?

November 20, 2022

On Sunday, 20 November 2022 at 01:07:14 UTC, zjh wrote:

>

In this way, just like a 'free functions', you can directly use the 'static' function in the 'class/struct'.

How about this?

For a specific function, you only need to give the syntax for opening a specific namespace such as 'enum/struct/class'etc. The existing syntax/tools will not be broken or not much damage.

November 20, 2022

On Sunday, 20 November 2022 at 01:11:49 UTC, zjh wrote:

>

For a specific function, you only need to give the syntax for opening a specific namespace such as 'enum/struct/class'etc. The existing syntax/tools will not be broken or not much damage.

With is not as good as using namespace std in C++, because with is for a statement, while usingcan be for a scope. In this scope/function, you can omit the prefix of struct/class/enum/....

November 19, 2022
On Sun, Nov 20, 2022 at 01:07:14AM +0000, zjh via Digitalmars-d wrote: [...]
> Can I open `one or more` 'enum' namespaces for a function, because sometimes, enum values are continuous,and you do not need `'switch'` statements. At this time, I still want to omit `'enum'` names' to use the `values`.
> 
> Similarly, can we also open the 'namespace' of `one or more` classes or structs for a function.
>
> In this way, just like a `'free functions'`, you can directly use the 'static' function in the 'class/struct'.
> 
> How about this?

This is exactly what `with` is designed for:

	enum MyLongEnum { LongValue, AnotherLongValue, YetAnotherLongValue }
	auto myFunc(Args...)(Args args) {
		with (MyLongEnum) {
			auto e = LongValue;
			... // etc.
		}
	}

Currently, `with` supports only one identifier; this could be enhanced to allow multiple identifiers so that you don't need to have 3-4 nested blocks just to have 3-4 implicit identifiers:

	enum MyLongEnum { ... }
	class MyClass { ... }
	struct MyStruct { ... }
	with (MyLongEnum, MyClass, MyStruct) {
		... // use members of all 3 without needing to spell them out every time
	}


T

-- 
Long, long ago, the ancient Chinese invented a device that lets them see through walls. It was called the "window".
November 20, 2022

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

>

Here in the discussion thread, you are free to discuss anything and everything related to the DIP. Express your support or opposition, debate alternatives, argue the merits, etc.

Not very interested, also would prefer:

    1. more explicit syntax for global scope .symbol (anything really)
      Even in C++ ::symbol is not self-explanating.
  • deprecate .symbol

  • reuse .symbol for that purpose eventually

November 20, 2022

On Sunday, 20 November 2022 at 01:26:25 UTC, H. S. Teoh wrote:

>

Currently, with supports only one identifier; this could be enhanced to allow multiple identifiers so that you don't need to have 3-4 nested blocks just to have 3-4 implicit identifiers:

enum MyLongEnum { ... }
class MyClass { ... }
struct MyStruct { ... }
with (MyLongEnum, MyClass, MyStruct) {
... // use members of all 3 without needing to spell them out every time
}

It's a little different. I don't want to wrap it with a {}.
I hope that the entire function scopecan be used directly without adding a prefix.
In my opinion, this is simpler,because most of the time enum are continuous. I can put enumerater handler functions into a vector(or array)(C++), but still add prefix, which is a bit troublesome.
It is very convenient if you do not add a prefix to the entire function scope.
For example:

enum longName{A,B,C};
struct longName2{
    static int g(){
        ...
    }
};
void f(){
    using longName;
    using gg=function<int(int)>;//C++
    gg[] fl;//gg
    fl[A],fl[B]...
    ...directly using A,B,C like this...;
}

void k(){
    using longName2;//struct/class
    ...directly using static g...
}

November 20, 2022

On Sunday, 20 November 2022 at 02:24:25 UTC, zjh wrote:

>

...

You only need to open the namespace of the enum/struct/class you need in the specific function. That is, when you cannot find the name/symbol, find the namespace opened by the user in the function. I think it should be easy for compiler writers.

November 20, 2022

On Sunday, 20 November 2022 at 02:30:17 UTC, zjh wrote:

>

You only need to open the namespace of the enum/struct/class you need in the specific function.

The syntax can be similar to:

using Aenum,Bclass,Cstruct;

You don't need brackets.

November 19, 2022
On 11/19/2022 5:11 PM, zjh wrote:
> For a specific function, you only need to give the `syntax` for opening a specific namespace such as `'enum/struct/class'`etc. The `existing syntax/tools` will not be broken or not much damage.

https://dlang.org/spec/statement.html#with-statement

In action:

https://github.com/dlang/dmd/blob/master/compiler/src/dmd/tokens.d#L607