Variable declaration primary expression

Paul Backus snarwin at gmail.com
Mon Jan 20 21:31:18 UTC 2025


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?

This sounds like a great feature for writing absolutely 
horrendous code.

Imagine: variables declared in the middle of function calls. 
Variables declared inside the initialization of other variables.

     struct Point
     {
         double x = (double y = 0);
     }

     void main()
     {
         import std.stdio;
         readf("%f, %f", (Point p).tupleof);
         writefln("p = (%f, %f)", p.x, p.y);
     }

Is this really what we want? If someone submitted code like this 
to one of your projects, would you accept it?


More information about the dip.ideas mailing list