[DIP idea] out variables

Max Haughton maxhaton at gmail.com
Tue Jan 26 20:59:04 UTC 2021


On Tuesday, 26 January 2021 at 01:01:54 UTC, Q. Schroll wrote:
> Main goal: Make the `out` parameter storage class live up to 
> promises.
> In current semantics, `out` is basically `ref` but with 
> documented intent. The initialization of the parameter is more 
> like a detail.
>
> [...]

A few thoughts,

I like the concept of out applied to lvalues to catch things 
being used too early.

The concept of introducing a new variable *inside* an expression 
sounds like a nightmare,
I think the following construct is not only easier to implement 
but also more generally applicable elsewhere in the language

if(out x; expr(x))
{

}

-- lowers to --
out x;
if(expr(x))
{

}


I have left out any types from the above, although deferred type 
inference could be very useful it would also have to be 
considered very carefully.

Also, finally, this would be yet another thing that rhymes with 
dataflow analysis in the core language, so it needs to be 
specified carefully.


More information about the Digitalmars-d mailing list