flint
flint copied to clipboard
Initialisation of dictionary contents.
During the course of implementing the tracking of keys inside dictionaries, I came across some behaviour that I would like to be clarified with regards to the initialisation of dictionary contents. Structs stored inside dictionaries appear not to be initialised on first use and I was wondering if this is intended behaviour or not. (Is it even possible to automatically initialise with the current system?) Similarly, there doesn't appear to be a nice way to delete dictionary entries - should this be implemented? Presumably this would also apply to nested dictionaries and not just structs, once they were implemented.
The reason this is relevant is because initialisation and deletion needs to be tracked as the keys array needs to be updated at that point.
We discussed the following syntax:
var dict: [Int: S]
dict[0] //Error if not declared
dict[0] = S() // Initialise on assignment
dict.delete(0) // Sets elements to zero
After discussing this issue, the correct approach would be to make dictionary values nillable and requre them to be initialised and deleted using special syntax in due course. However, for now, implementing dictionary keys in the same way as dynamic array lengths would be appropriate.