4 ms·
immutability? Interactive Elixir (1.19.0) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> x = 1 1 iex(2)> x = 2 2 iex(3)> Wha
by cyberpunk 1y ago
immutability?
Interactive Elixir (1.19.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> x = 1
1
iex(2)> x = 2
2
iex(3)>
What's immutable about elixir? It's one of the things which I MISS from Erlang -- immutability.
- nitros 1y agoThis is like saying Haskell doesn't have immutability because it has the state monad, or that rust doesn't because you can shadow with let. Data is immutable and thats much more important than whether local variables can be modified imo.
- deleted 1y ago[deleted]
- debugnik 1y agoShadowing is not mutability. The former isn't affected by control flow nor does it affect closures.
- int_19h 1y agoWhat you wrote is roughly equivalent to this in C: { const int x = 1; { const int x = 2; } } which is to say, there are two different `x` in there, both immutable, one shadowing the other. You can observe this if you capture the one that is shadowed in a closure: iex(1)> x = 1 1 iex(2)> f = fn () -> x end #Function<43.113135111/0 in :erl_eval.expr/6> iex(3)> x = 2 2 iex(4)> f.() 1