Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not disagreeing with you, but it's worth noting that tuples support random O(n) access by index. They can therefore be used in place of arrays for some simple applications.


Tuples can be up to 16,777,215 elements, so quite substantial applications.

https://www.erlang.org/doc/system/system_limits

There is also some hope that future versions of the Erlang compiler will allow mutable O(1) update of tuple elements through setelement (code inside a process is - almost - guaranteed not to have shared references).

  Safe destructive update of tuples has been implemented
  in the compiler and runtime system. This allows the VM to
  update tuples in-place when it is safe to do so, thus 
  improving performance by doing less copying but also by 
  producing less garbage.
https://github.com/erlang/otp/releases?q=27&expanded=true

It should be possible to add Elixir syntactic sugar to make this more concise and natural.


> random O(n) access

O(1) for reading I believe. The slightly awkward array module is built on top of tuples, a 10-tree of tuples? or something like it.

But good point, once in a while I see list_to_tuple to provide faster indexed reads on lists.


Are you sure you mean O(n) instead of O(1), which I would expect for an array?


Oops! Yes, O(1). Too late to edit, unfortunately.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: