First Draft: Static Single Assignment

Peter C peterc at gmail.com
Wed Dec 3 22:21:53 UTC 2025


On Wednesday, 3 December 2025 at 10:53:04 UTC, Dom Disc wrote:
> On Wednesday, 3 December 2025 at 10:43:53 UTC, Peter C wrote:
>> On Wednesday, 3 December 2025 at 10:18:50 UTC, Nick Treleaven 
>> wrote:
>>> Just to note that final on a dynamic array `a` should mean 
>>> that `a.ptr` and `a.length` never change, but elements e.g. 
>>> `a[0]` can change. So if final was allowed on fields, both 
>>> assignments above would error.
>>
>> Yes, I forgot how dynamic arrays work.
>
> This doesn't seem to be very useful. If you want a dynamic 
> array that can't change length, why don't you use a static 
> array?!?

Essentially I was trying to do this in D (below is C# though)

using System;
using System.Collections.Generic;

class Buffer
{
     public readonly List<int> data = new List<int>();
}

internal static class Program
{
     static int Main()
     {
         var buf = new Buffer();
         buf.data.Add(42);

         // error CS0191: A readonly field cannot be assigned to 
(except in a constructor or a variable initializer)
         //buf.data = new List<int>();

         return 0;
     }
}




More information about the dip.development mailing list