First Draft: ref For Variable Declarations

Quirin Schroll qs.il.paperinik at gmail.com
Fri Apr 26 09:52:07 UTC 2024


On Friday, 12 April 2024 at 20:43:50 UTC, Walter Bright wrote:
> https://github.com/WalterBright/documents/blob/984374ca885e1cb10c2667cf872aebc13b4c1663/varRef.md

Why only `ref`?

`ref` on local variables is much more like `ref` on a parameter 
than a returned object. For parameters, `ref` is one of three: 
The others are `in` and `out`. Why not also include `in`? It 
seems unrelated, but it’s only slightly more general.

An `in` parameter is `const scope`, can bind rvalues, and is 
`ref` unless the type is small, then it’s a copy. That’s nothing 
a local variable couldn’t be and the “copy-if-small” semantic 
isn’t even easily mimicked.

As for `out` I had some ideas, but those are indeed unrelated 
with the DIP. (An `out` local variable would have to be 
uninitialized and have to be *initialized* (not assigned) before 
it is read. The most compelling use case is passing such a 
variable to a function `out` parameter.)


More information about the dip.development mailing list