4 ms·
Last I checked, Erlang strings were represented internally as a linked list of integers, one int for every character. That worked, but I felt like not every ef
by habibur 1y ago
Last I checked, Erlang strings were represented internally as a linked list of integers, one int for every character.
That worked, but I felt like not every efficient, as web is very text heavy.
Has that changed in the later versions?
- zerr 1y agoIn Elixir it's bytestring.
- finder83 1y agoI believe that's still true of Erlang, but Elixir has UTF-8 encoded strings. In practice the only time you need to use Erlang strings from Elixir is if you're using an Erlang API.
- waynesonfire 1y agoBoth Erlang and Elixir support two types of text representations. The first is a linked list of Unicode codepoints (also called a character list or a charlist for short). In Erlang, this is written using double quotes. For example, "abc" in Erlang is actually the list [97, 98, 99]. In Elixir, the same representation uses single quotes: 'abc' is a list of integers. The second is a UTF-8 encoded binary. In Erlang, this is written using the <<"abc">> syntax. In Elixir, double quotes represent UTF-8 binaries, so "abc" is a binary. So: Erlang "abc" = list, <<"abc">> = binary Elixir 'abc' = list, "abc" = binary For efficiently handling textual data, Phoenix extensively utilizes iolists (https://hexdocs.pm/elixir/1.15.8/IO.html#module-io-data https://hexdocs.pm/elixir/1.15.8/IO.html#module-io-data) to eliminate copying. It's used in performance critical areas such as generating http responses and template rendering. In general, on the Erlang VM, iolists are a first-class, widely used data structure for efficient I/O.