Runtime-calculated default values for structs

I might not have described my point very well. My argument is that all elixir syntax for the different datatype we have evaluate to a statically known value. To me %Struct{} is no different to writing 4 or {:ok, 20}. I’m not getting 20 when writing 4. I’m very aware of the fact that struct definitions can be changed, but at least all of the possible changes are scoped to compiling the definition again. That’s the price to be payed for user-defined data, the user can define the data. Maybe explained a different way: %Struct{} == %Struct{} is a property I don’t want to have violated just like [] == [] or {:ok, 20} == {:ok, 20} always holds true. Structs outliving their code definition – and thereby becoming %{__struct__: Struct, …} – is imo bad enough already.

3 Likes