3 ms·
It's not just you, this is an issue with the BEAM platform itself. Singly-linked lists are the privileged sequential datastructure on the BEAM. I work in Elixir
by asa400 2y ago
It's not just you, this is an issue with the BEAM platform itself. Singly-linked lists are the privileged sequential datastructure on the BEAM. I work in Elixir every single day and this is one of my pet peeves about the platform.
There actually are arrays [1] and ETS tables [2] that allow for fast random access and updates but they don't have first-class syntax in Erlang, Elixir, or (it seems) Gleam. They're just libraries, so you can't pattern match on them. And when it comes to the array datatype, approximately no one uses it. I don't think I've ever seen code in the wild that uses it.
I don't know why they don't build a first-class random-access vector datastructure like Clojure [3] that has a superset of BEAM's list functionality. I think at this point it's mostly just historical inertia: list has been there so long it would be a massive pain to change it.
[1] https://www.erlang.org/doc/apps/stdlib/array.html https://www.erlang.org/doc/apps/stdlib/array.html
[2] https://www.erlang.org/docs/23/man/ets https://www.erlang.org/docs/23/man/ets
[3] https://clojure.org/reference/data_structures#Vectors https://clojure.org/reference/data_structures#Vectors