DEV Community

Discussion on: Which Data Structure Should I Use? An Elixir Cheat Sheet

 
thepeoplesbourgeois profile image
Josh • Edited

I nearly had a heart attack when you declared lists and tuples basically the same thing.

In the Erlang VM, a tuple is always stored as a contiguous segment of memory – the item at index n is stored at the memory address right after where n-1 ended. As such, it's generally very bad form to do a lot of modifying of tuple content and structure, as a good number of those operations will result in data being copied and collated at a new memory address.

Contrast this to lists, which the Erlang VM keeps track of by storing a reference to the previous data point's address alongside the current data point. As such, not only is the length of a list dynamic, its addresses within RAM are, too (and the newest data is, paradoxically, usually at the leftmost side of the list).

tl;dr, Erlang doesn't make lists out of syntactic tuple sugar, because that would be madness