January 06, 2023

On Thursday, 5 January 2023 at 22:49:01 UTC, thebluepandabear wrote:

> >

Have fun reading this :

https://issues.dlang.org/show_bug.cgi?id=21929

Thanks for the code suggestion although it still doesn't fix the bug. I am curious as to what those brackets do as well.

Okay, my bad for writing the wrong code, the correct one is:

 foreach (BoardSize boardSizeIter; arr) (Boardsize boardSize){ // notice the brackets and I changed the variable names a little
     Button button = new Button();
     button.text = format("%sx%s", boardSize[0], boardSize[1]);
     button.onButtonClick = {

 eventHandler.settingsWindow_onBoardSizeButtonClick(boardSize);
     };
     button.onButtonClick();
     _boardSizeRow.addChild(button);
 }(boardSizeIter) // notice the brackets and that I changed the name of you first foreach argument

This will do the same thing as HS Teoh and Tsbockman's code did : create a copy of the value that is currently present in one particular iteration of the foreach by creating a function literal that takes your struct as a paramter. This works because structs are value types, so passing it to the function creates a copy.

January 09, 2023
> A nested function (or perhaps an inline lambda) is needed to force the allocation of a dynamic context for the capture.
>
> This is an embarrassment. Why hasn't this been fixed yet? :-(
>
>
> T

I agree that this needs to get fixed immediately, it seems to be bugging me another time as well.

I believe I saw a similar StackOverflow post about this issue for C#, and Microsoft did fix it, hopefully D can do the same. Fixing this will improve the quality of the language for newcomers such as myself greatly.
January 09, 2023
> Fixing this will improve the quality of the language for newcomers such as myself greatly.

This not only confuses newcomers but it gave a false illusion of a bug within the code :/
January 09, 2023
>

: create a copy of the value that is currently present in one particular iteration of the foreach by creating a function literal that takes your struct as a paramter. This works because structs are value types, so passing it to the function creates a copy.

Thanks, your solution seems to be the most elegant one yet, I recently came across the similar problem and I realized that the other answer was too long and verbose.

January 09, 2023
On Monday, 9 January 2023 at 00:19:39 UTC, thebluepandabear wrote:
>> Fixing this will improve the quality of the language for newcomers such as myself greatly.
>
> This not only confuses newcomers but it gave a false illusion of a bug within the code :/

It doesn't confuse newcomers only, also people who have used D for over a decade like me :) Mostly because it's not a thing in most (if not all) other languages.

I think D is unique in that aspect.

It should be fixed however, I don't think the current behavior is correct or expected by anyone.
1 2
Next ›   Last »