Re: DIP1046, "ref For Variable Declarations", has been Accepted

2024-06-24 Thread Mike Shah via Digitalmars-d-announce

On Monday, 24 June 2024 at 11:08:32 UTC, Nick Treleaven wrote:
On Sunday, 23 June 2024 at 21:50:37 UTC, Vladimir Marchevsky 
wrote:

On Sunday, 23 June 2024 at 13:29:21 UTC, Mike Parker wrote:

[...]



[...]


Does ref add anything compared to using an alias?..


`ref` will bind to lvalue expressions, e.g (from the DIP):

```d
ref int dark(ref int x, int i, int* q)
{
ref m = *q;// m refers to whatever q points to
...
}
```

`*q` is an expression, not a symbol. `ref` can bind to e.g. a 
struct field runtime value, or an lvalue returned from a 
function.


`alias` only allows giving new names for existing compile-time 
symbols.


This is welcoming news! A nice addition for folks transitioning 
over from C++ who are use to having this functionality.


Re: DIP1046, "ref For Variable Declarations", has been Accepted

2024-06-24 Thread Nick Treleaven via Digitalmars-d-announce
On Sunday, 23 June 2024 at 21:50:37 UTC, Vladimir Marchevsky 
wrote:

On Sunday, 23 June 2024 at 13:29:21 UTC, Mike Parker wrote:

DIP1046, "ref For Variable Declarations", has been accepted:

https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1046.md


which reduces the complexity of the code, as long-winded 
global names get a shorthand


Does ref add anything compared to using an alias?..


`ref` will bind to lvalue expressions, e.g (from the DIP):

```d
ref int dark(ref int x, int i, int* q)
{
ref m = *q;// m refers to whatever q points to
...
}
```

`*q` is an expression, not a symbol. `ref` can bind to e.g. a 
struct field runtime value, or an lvalue returned from a function.


`alias` only allows giving new names for existing compile-time 
symbols.