First Draft: ref For Variable Declarations

Dukc ajieskola at gmail.com
Fri Apr 19 08:53:40 UTC 2024


On Friday, 19 April 2024 at 07:23:22 UTC, Nick Treleaven wrote:
>
> The behaviour could perhaps be defined as follows - if this 
> would compile:
> ```d
> (ref p) { CODE }(lvalue);
> ```
> Then, with some restrictions on `CODE`, you can write:
> ```d
> ref p = lvalue;
> CODE
> ```
> And the effects will be equivalent. `CODE` cannot contain 
> `return` statements or `__traits(parameters)`, 
> `__traits(parent)`, `is(T PS == __parameters)` expressions. 
> Have I missed anything else?

This formulation works IMO but it's better to just write the 
expression used to initialise the `ref` variable must be an 
lvalue, lvalue meaning a value with a memory address. The spec 
already uses "lvalue" and "rvalue" and includes them in the 
glossary so it's not a problem.




More information about the dip.development mailing list