First Draft: Static Single Assignment

Peter C peterc at gmail.com
Fri Nov 21 09:48:57 UTC 2025


On Thursday, 20 November 2025 at 06:03:03 UTC, Walter Bright 
wrote:
> On 11/15/2025 6:43 PM, Richard (Rikki) Andrew Cattermole wrote:
>> Three things I'd like to see here:
>> 
>> 1. Function parameters
>
> Yes
>
>
>> 2. Fields
>
> Problematic, because one can modify it with some pointer 
> manipulation
>
>
>> 3. Globals
>
> Yes

and forloops?

-----
module mymodule;
@safe:
private:
import std;

void main()
{
     int[] arr = [100, 200, 300];
     int extra = 999;

     // Here, 'fixed' ensures that the loop variable remains bound
     // to the correct array element throughout its iteration.
     //
     foreach (fixed ref element; arr)
     {
       // element is now bound as an alias to arr[i]

       element = 500; // OK: modifying the value being referenced 
-> arr[i]
       element = extra; // ERROR: reassigning a fixed reference 
binding is not allowed.
     }
}

-----


More information about the dip.development mailing list