First Draft: ref For Variable Declarations

Walter Bright newshound2 at digitalmars.com
Fri Apr 12 21:42:16 UTC 2024


On 4/12/2024 2:16 PM, Richard (Rikki) Andrew Cattermole wrote:
> - "Enable local variables do be declared as ref."
> 
> s/do/to/
> 
> - Are they automatically scope as well?

Scope would apply to what the ref points to, not what the ref is.


> - So this doesn't support borrowing from a data structure?
> 
> Why not?

Inability to control the lifetime.

> Closing what I call DIP1000's last big hole, would allow this.
> 
> ```d
> DS ds = ...;
> Wrapper wrapper = ds[...];
> ref item = wrapper.get;
> 
> wrapper.destroy;
> item.writeln; // error
> ```
> 
> This would be awesome to have.

Since you can pass wrapper.get to a ref parameter to a function, this already works.


> - What is the point of this if the previous point isn't it?

??

> An alias would be more appropriate for the example given.

??


More information about the dip.development mailing list