Mutability in jakt is modeled around value semantics, i.e. if one copies an immutable value such as a number or a struct instance the copy can be mutable:
let a = 1
mut b = a
b = 2
which is totally fine. However classes and boxed enums have reference semantics, so chaning the "copy" will also changed the "copied" value, because it was not in fact copies. To fix this two things would have to be changed:
for the latter again I see three possibilities
const
qualifier for return typesmut
qualifierthe latter could actually be combined with one of the other two
To really make using immutable instances safe imho it would have to be guarantueed that all variables holding a reference to an instance are immutable. That means either an instance would have to be immutable at construction time and then it should also not be possible to assign it to a mutable variable. or assigningments chaning mutability would have to assert that the reference count is 1.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too