binary dot assignment
Quirin Schroll
qs.il.paperinik at gmail.com
Thu Feb 13 22:32:09 UTC 2025
On Monday, 30 December 2024 at 21:33:58 UTC, Basile B. wrote:
> If you look long enough at some code you'll see patterns like
>
> ```d
> a = a.b;
> ```
>
> this pattern strangely looks like binary assignment operators
>
> ```d
> a = a + b;
> ```
>
> which can be rewritten as
>
> ```d
> a += b;
> ```
>
> In the same fashion we could have
>
> ```d
> a .= b;
> ```
>
> The point is to evaluate te left hand side only once.
It *will* fool newcomers into thinking `.` is a binary operator,
but it’s not. The right-hand side cannot ever be something other
than an *Identifier* followed by something. I don’t think I have
ever seen someone put spaces around `.` exactly because of that.
More information about the dip.ideas
mailing list