DIP1000: Walter's proposal to resolve ambiguity of ref-return-scope parameters

Imperatorn johan_forsberg_86 at hotmail.com
Thu Nov 25 21:08:37 UTC 2021


On Thursday, 25 November 2021 at 20:45:41 UTC, Stanislav Blinov 
wrote:
> On Thursday, 25 November 2021 at 16:11:39 UTC, Dennis wrote:
>> On Thursday, 25 November 2021 at 15:57:13 UTC, WebFreak001 
>> wrote:
>>> with `return ref` and `return scope`, will there also be a 
>>> `return this` for the case like the opIndex functions 
>>> returning something with the lifetime of the containing 
>>> struct? I don't quite get how it's otherwise fixing it.
>>
>> `return this` in struct member functions is `return ref`. 
>> Walter proposes in the bugzilla issue to allow `ref` after the 
>> parameter list:
>>
>> ```D
>> struct S {
>>     ref int opIndex() return ref scope {
>>
>>     }
>> }
>> ```
>
> Jesus... Recall how, at that one DConf, Scott Meyers suggested 
> that D would be wise to not require a Scott Meyers? Well what 
> do you know, if you have
>
> ```d
> ref what() return;
> ref the() return scope;
> ref fuck() return ref scope;
> ```
>
> all in the same language, then you'd need a Meyers-Sutter 
> hybrids mass-cloned 24/7 in a specialized facility for the sole 
> purpose of teaching this stuff, if you want the language to get 
> anywhere. And some enslaved clones of Andrei locked away in a 
> basement, churning out book after book titled "Writing code 
> that don't not work". Something stinks something fierce here.
>
> https://dlang.org/spec/function.html#parameters needs to get 
> __simpler__, not turn into a PhD thesis, which it is already 
> well on the way to.

Don't forget 😁
```d
ref what() return;
ref the() return scope;
ref fuck() return ref scope;

auto ref what() return;
auto ref the() return scope;
auto ref fuck() return ref scope;

auto ref f1(int x)     { return x; }  // value return
auto ref f2()          { return 3; }  // value return
auto ref f3(ref int x) { return x; }  // ref return
auto ref f4(out int x) { return x; }  // ref return
auto ref f5() { static int x; return x; }

// etc
```


More information about the Digitalmars-d mailing list