5 ms·
Hmmm, the tutorial seems to suggest its strings are linked lists of characters. Is that true?
by ivoras 10y ago
Hmmm, the tutorial seems to suggest its strings are linked lists of characters. Is that true?
- qaq 10y agothose exist for compatibility with Erlang. Elixir strings are UTF-8 encoded binaries.
- querulous 10y agoerlang 'strings' are utf-8 encoded binaries also, they just have slightly terrible syntax
- _asummers 10y agoYou have two -- charlists like you're describing, which are just linked lists of characters under the hood and UTF-8 binaries. Charlists are denoted with single quotes and the UTF-8 ones are denoted with double quotes. Truthfully, I reach for the UTF-8 ones most of the time, but you can get some good performance gains in e.g. template string building in web frameworks if you use charlists. In Erlang, all the strings work like charlists FWIU, so they need to exist at least in some capacity for interop reasons. http://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html http://elixir-lang.org/getting-started/binaries-strings-and-...
- anuragsoni 10y agoAre you thinking of IO lists[0] when you talk about templates with respect to web frameworks? [0] https://www.bignerdranch.com/blog/elixir-and-io-lists-part-2-io-lists-in-phoenix/ https://www.bignerdranch.com/blog/elixir-and-io-lists-part-2...
- _asummers 10y agoI totally am and now I look silly :) Good catch.
- anuragsoni 10y agoNot at all :) If you haven't read that post by bignerdranch, i'd definitely recommend it. It was interesting read (both parts 1 and 2)
- TylerE 10y agoLinked list strings are not necessarily terrible in a language with immutable data like Elixir.
- yellowapple 10y agoIf you want them to be, yes. Erlang's normal "string" type is indeed a list of integers representing codepoints. Erlang also supports "bitstrings" or "binary strings", which are basically what most other languages would just call "strings", as a logical extension of its existing binary data syntax. Elixir instead uses Erlang "bitstrings" as its default "string" type. Erlang integer-list-based "strings" are represented in Elixir by using single-quotes instead of double-quotes around such a string (or by just manipulating a list directly; Elixir will transparently convert a list of integers into an Erlang-style charlist if the integers are valid codepoints).