Variable declaration primary expression
IchorDev
zxinsworld at gmail.com
Tue Jan 21 20:51:20 UTC 2025
On Tuesday, 21 January 2025 at 16:59:12 UTC, Andre wrote:
> On Monday, 20 January 2025 at 20:41:42 UTC, IchorDev wrote:
>> Someone brought up this clever idea here:
>> https://github.com/dlang/dmd/pull/20653#issuecomment-2581474608
>> What does everyone think about being able to declare variables
>> in expressions? Is there any pre-existing syntax that blocks
>> us from being able to easily do this?
>
> If I understand it correctly this would solve my issue
> https://github.com/dlang/dmd/issues/18890
>
> ```d
>
> with (auto p = new Panel())
> {
> parent = this;
> text = "bla";
> with (new Button())
> {
> parent = p; // Here p is needed
> text = "bla2";
> }
> }
> ```
>
> The syntax `with (auto p = new Panel())` is currently not
> allowed.
That’s a very clever use of the syntax. I don’t see why that
shouldn’t work.
More information about the dip.ideas
mailing list