optional assignment
Basile B.
b2.temp at gmx.com
Tue Dec 31 02:12:59 UTC 2024
On Tuesday, 31 December 2024 at 00:38:56 UTC, monkyyy wrote:
> On Monday, 30 December 2024 at 15:07:41 UTC, Basile B. wrote:
>> A common pattern in a world where `null` exists is
>>
>> ```d
>> if (!a)
>> a = b;
>> ```
>>
>> that is semantically equivalent, if `a` is a pointer (or if it
>> implements opCast!bool), to D
>>
>> ```d
>> if (a is null)
>> a = b;
>> ```
>>
>> I propose the get rid of the statement layer. The two
>> statments (there are more actually) can be a single expression:
>>
>> ```d
>> a ?= b;
>> ```
>>
>> As a new binary assign operator.
>
> https://forum.dlang.org/thread/nmwzohfqqyajahkncreq@forum.dlang.org
I use it since monthes in styx. It's one of the best thing that's
possible just right now in D. Otherwise I would not propose it.
For a long time I thought optional access was really the shit,
but at some point I implemented a programming language, and now
I'm pretty sure that is the best niche expression.
More information about the dip.ideas
mailing list