This is why Haskell (ST)
and Clojure (transients) provide local mutable state in the form of "linear types" where it is impossible to read a mutable value outside of tightly controlled conditions.
As Guy Steele wrote, "Lambda, the ultimate imperative"
As Guy Steele wrote, "Lambda, the ultimate imperative"