Erlang / Erlang Basics Interview questions
Define immutability in Erlang?
In Erlang, once a variable is bound to a value it can never be reassigned within that scope — there is no mutation, only rebinding through a new variable name or a new function call. This applies to every data structure: lists, tuples, and maps are all persistent; "changing" one actually builds a new copy with the edit applied.
X = 5, X = 6. %% fails: X is already bound to 5, this is NOT reassignment
Immutability removes an entire category of bugs — no function can silently corrupt data another function is holding a reference to, and no two processes can race over the same mutable cell, since there isn't one.
The tradeoff is that "updating" a large structure means allocating a new version of it, so Erlang leans on structural sharing and per-process garbage collection to keep that cheap in practice.
More Related questions...