braceless with statements
Dr Machine Code
jckj33 at gmail.com
Fri Nov 12 19:45:04 UTC 2021
On Friday, 12 November 2021 at 10:55:21 UTC, Stefan Koch wrote:
> Good Morning Everyone,
>
> I recently found myself wanting to introduce a bunch of member
> variables into the scope of the function I was currently
> working on.
> Of course D has a nice way to do that; The `with` statement.
>
> so
> ```D
> struct S { int x; }
> int fn()
> {
> S s;
> with(s)
> {
> x = 12;
> return x;
> }
> }
> ```
>
> this code works but it forces another level of indentation
> which makes it a little ugly.
>
> So I did a small patch to my local version of dmd.
Do you use your own compiler version? do use it for anything but
toy projects?
> And now this works:
> ```D
> struct S { int x; }
> int fn()
> {
> S s;
> with(s):
> x = 12;
> return x;
> }
> ```
>
> It is a really simple patch and I think it's worthwhile to have
> this in the main language.
it's lowered to the very same code in your first example, right?
tbh honest I like it, wouldn't mind that in the main language. I
think this one of the syntax sugar examples that didn't make it
hard and/or ugly to read
More information about the Digitalmars-d
mailing list