Closed flofriday closed 2 years ago
Oh, I thought I made i
immutable, so only the loop can internally change its value...
It is true that i is immutable inside the loop, but still it feels like i
is declared here and then mutated on each iteration.
This is not how it is implemented but it I thing we should force it to be mutable.
I mean languages that are purely functional don't have for each loops for exactly this reason, because i
would get mutated.
It was mutable before... With the last commit I made it immutable. At least this is how Swift handles this
We could do it in a different way of course
The following code is allowed by the typechecker:
Obviously it mutates
i
but the typechecker still allows this. We however should requirea mutable variable on the left side ofin
.