D needs a type expression syntax

Quirin Schroll qs.il.paperinik at gmail.com
Sat May 6 16:31:40 UTC 2023


On Friday, 5 May 2023 at 16:26:38 UTC, Basile B. wrote:
> On Friday, 5 May 2023 at 15:11:50 UTC, Nick Treleaven wrote:
>> On Thursday, 4 May 2023 at 15:40:20 UTC, Quirin Schroll wrote:
>>> [...]
>>
>> It could be trailing return type syntax:
>> ```d
>> function(ref int i) -> ref int refIdPtr;
>> ```
>> Then we don't need the `alias A = ref T` rule, and we can keep 
>> parentheses for expressions (including tuples in future).
>>
>> [...]
>
> IMO the big problem here, so with `const` is that `const` 
> cannot be put for an hidden parameter...
>
> That's essentially why this strange syntax exists.

To be honest, I don’t understand what you mean. Given a delegate 
(not a function) You can put `const` between the closing 
parenthesis and the arrow or after the arrow before the 
`BasicType`:
```d
       delegate(ref int i) const -> ref       Object dg1;
const delegate(ref int i) const -> ref       Object dg2;
       delegate(ref int i)       -> ref const Object dg3;
```

`dg1` returns a mutable Object, its context won’t be changed when 
invoked.
`dg2` returns a mutable Object, its context won’t be changed when 
invoked; `dg2` cannot be reassigned.
`dg3` returns a const Object.

This is not an issue in any way.


More information about the Digitalmars-d mailing list