Double bracket "{{" for scoping static foreach is no longer part of D

rikki cattermole rikki at cattermole.co.nz
Wed Dec 22 16:01:49 UTC 2021


Seems to be working just fine as of 2.098.

```d
import std;
void main()
{
     static foreach(Foo; ["Abc", "def"]) {{
         string str = Foo;
     	writeln("Hello D ", str, __VERSION__);
     }}
}
```

```
Hello D Abc2098
Hello D def2098
```

Anyway, AliasAssign has nothing to do with this. This "trick" creates a 
closure aka ``() { ... }``. Thats all its doing.

 From the AST dump:

```
import object;
import std;
void main()
{
	{
		string str = "Abc";
		writeln("Hello D ", str, 2098L);
	}
	{
		string str = "def";
		writeln("Hello D ", str, 2098L);
	}
	return 0;
}
```


More information about the Digitalmars-d-learn mailing list