3 ms·
erlang is not fundamentally immutable. It's just "locally immutable". You can't mutate a variable. A function call can have side effects, just it can't chang
by dnautics 5y ago
erlang is not fundamentally immutable. It's just "locally immutable". You can't mutate a variable. A function call can have side effects, just it can't change its arguments -- but if it's argument is, abstractly speaking, a reference [0], it can effect a change on the abstract contents of the reference. Using this mechanism there are TONS of escape hatches using function-called "abstract references".
[0] maybe the reference refers to a file, network socket, a url over the internet, which work in the obvious way. It could also be things that erlang gives you for free: the id to another process (thread) to which you send an instruction, "change your internal data", a "process dictionary" (think: thread-local-storage ish), "ets tables" (think: a redis/memecached you get for free"). If you want to go deeper, it could even be "a wrapped, refcounted, C pointer to raw memory", there are ways to do this safely that the native interface gives the curious low-level programmer.