8 ms·
If this is your cup of tea, you should also take a look at Gleam.
by leke 2y ago
If this is your cup of tea, you should also take a look at Gleam.
- steve_adams_86 2y agoI tried using gleam for real work the other day and found myself really enjoying it. It's a cool language and surprisingly productive coming at it with no experience with OTP or the BEAM. I know it's a me issue, but I got stumped by how inefficient it is to write code that handles linked lists in some cases. As far as I can tell, there's no built-in array or anything more convenient. I had to write a function to find items at indices, haha. I looked through the docs and it seems like I'm not missing anything. I'm clearly too accustomed to web development https://hexdocs.pm/gleam_stdlib/gleam/list.html https://hexdocs.pm/gleam_stdlib/gleam/list.html
- leke 2y agoYou should also try to reach out on the Discord channel. They're a very friendly community.
- steve_adams_86 2y agoThat’s a great idea, thanks for the suggestion!
- ramchip 2y agoTuples are the BEAM's native arrays, but they're expensive to update, immutability means you (usually) have to copy the whole thing to update one index. Lists are a lot more common in functional languages. If you really need random access you can use a map with integer keys. If you want to write numerical stuff, Elixir has Nx - not sure if it's usable from Gleam though.
- asa400 2y agoIt'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