www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - ref locals

reply Manu <turkeyman gmail.com> writes:
This is kinda rhetorical, since I've asked this a million times, and we all
know the answer... but seriously; why can't we declare ref locals?

Lots of functions return a ref; and we need to capture the result of those
functions appropriately.

ref T f();

void t()
{
  ref T result = f();  // <-- there's no good reason to reject this
}

I don't understand why this doesn't come up every few days, everytime a new
user appears. Is this really okay? Why does this make me feel so
frustrated, but nobody else seems to care?

... "Use a pointer!" ...

void t()
{
  T* result_ptr = &f();  // seriously?
}

I feel embarrassed by this suggestion, why don't you feel embarrassed by
this suggestion?
It's also pretty shit that taking a pointer of a function's result like
that is not compatible with ufcs, where it instead attempts to create a
function pointer.

It gets worse when the function is property-like.

void t()
{
  T* prop_ptr = &myThing.prop;
}

error: cannot implicitly convert expression `& f` of type `T delegate()
ref` to `T*`

A new D user will look at that and think it's stupid... at least; I look at
that and I think it's stupid!
ref locals already please, this has gone on long enough!
Aug 14
next sibling parent reply Bruce Carneal <bcarneal gmail.com> writes:
On Wednesday, 14 August 2024 at 14:26:34 UTC, Manu wrote:
 This is kinda rhetorical, since I've asked this a million 
 times, and we all know the answer... but seriously; why can't 
 we declare ref locals?

 ...
The "Second Draft: ref for Variable Declarations" thread in the "DIP Devel" forum might be useful.
Aug 14
parent Bruce Carneal <bcarneal gmail.com> writes:
On Wednesday, 14 August 2024 at 15:59:16 UTC, Bruce Carneal wrote:
 On Wednesday, 14 August 2024 at 14:26:34 UTC, Manu wrote:
 This is kinda rhetorical, since I've asked this a million 
 times, and we all know the answer... but seriously; why can't 
 we declare ref locals?

 ...
The "Second Draft: ref for Variable Declarations" thread in the "DIP Devel" forum might be useful.
PS: I'm a fan of your work. If you're headed to DConf I'd enjoy talking. If not maybe DM via discord?
Aug 14
prev sibling parent reply Nick Treleaven <nick geany.org> writes:
On Wednesday, 14 August 2024 at 14:26:34 UTC, Manu wrote:
 This is kinda rhetorical, since I've asked this a million 
 times, and we all know the answer... but seriously; why can't 
 we declare ref locals?
https://dlang.org/changelog/pending.html#dmd.reflocal
Aug 14
next sibling parent Marcus <marcus example.com> writes:
On Wednesday, 14 August 2024 at 20:06:49 UTC, Nick Treleaven 
wrote:
 On Wednesday, 14 August 2024 at 14:26:34 UTC, Manu wrote:
 This is kinda rhetorical, since I've asked this a million 
 times, and we all know the answer... but seriously; why can't 
 we declare ref locals?
https://dlang.org/changelog/pending.html#dmd.reflocal
We are so back.
Aug 14
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
OMFG, this is a truly glorious day, and what a delightful coincidence!
Thank the gods for their terribly late but eventual insight!

On Thu, 15 Aug 2024 at 06:11, Nick Treleaven via Digitalmars-d <
digitalmars-d puremagic.com> wrote:

 On Wednesday, 14 August 2024 at 14:26:34 UTC, Manu wrote:
 This is kinda rhetorical, since I've asked this a million
 times, and we all know the answer... but seriously; why can't
 we declare ref locals?
https://dlang.org/changelog/pending.html#dmd.reflocal
Aug 14
prev sibling parent Manu <turkeyman gmail.com> writes:
On Thu, 15 Aug 2024 at 09:53, Manu <turkeyman gmail.com> wrote:

 OMFG, this is a truly glorious day, and what a delightful coincidence!
 Thank the gods for their terribly late but eventual insight!
Is it too late to get the -preview=rvaluerefparam change into 2.111 as well? It looks like the release is running late, but that would really round the whole thing out! :P
Aug 14