If you could make any changes to D, what would they look like?

Dukc ajieskola at gmail.com
Wed Oct 27 19:38:17 UTC 2021


On Wednesday, 27 October 2021 at 19:26:57 UTC, IGotD- wrote:
> On Wednesday, 27 October 2021 at 19:19:31 UTC, Dukc wrote:
>>
>> `pure` is also supposed to be an optimization aid.
>
> It would be interesting to see an example of how pure can help 
> optimization, compared to if you wouldn't badge the function.

For example, with that `coming` function, the compiler may rewrite
```d
foreach(unused; 0 .. 4) coming.writeln;
```
to
```d
auto comingRes = coming;
foreach(unused; 0 .. 4) comingRes.writeln;
```
.

In fact, the compiler can even evaluate `coming` at compile time, 
and avoid any function call at all:
```d
foreach(unused; 0 .. 4)
{  //or any other short value
    29677.writeln;
}
```


More information about the Digitalmars-d mailing list