Sihui Huang edited this page Jun 8, 2018 · 35 revisions

1. What are the main problem domains Elixir is suitable for?

In short:

  • data processing
  • network related tasks: from plain sockets to web servers and frameworks
  • writing reliable, distributed, and highly available software.

2. Can Elixir be used to write programs that rely heavily on fast numerical computations?

Elixir will most likely show worse performance compared to a compiled imperative language when performing a strictly sequential (CPU) or uniformly parallel (GPU) computation. However, there are lots of use-cases where Erlang's concurrency features (that Elixir takes full advantage of) might be put to good use in mathematical computation contexts.

Here are a few resources on the subject that describe technical computing in Erlang (applies to Elixir as well).

  • From Telecom Networks to Neural Networks; Erlang, as the unintentional Neural Network Programming Language [video]
  • High-performance Technical Computing with Erlang [slides]
  • When does Erlang's parallelism overcome its weaknesses in numeric computing? []
  • Go, F# and Erlang -- implementation of matrix multiplication and prime number test in each of the three languages [paper]

3. How do I start a shell (IEx) with my project and all its dependencies loaded and started?

iex -S mix inside your project's directory.

3.1. How to have my IEx session history to be persistent over different IEx sessions?

If you have OTP 20 or greater installed you can run export ERL_AFLAGS="-kernel shell_history enabled" from your shell's profile.

Otherwise, there's a very nice module [erlang-history] that does the trick for both elixir and erlang shells.

4. Why is my list of integers printed as a string?

For example:

iex(1)> [27, 35, 51]

Pretty-printing of lists is done by using Erlang's native function. It is designed to print lists as strings when all elements of the list are valid ASCII codes.

You can avoid this by appending 0 to your list, or by disabling char list printing:

iex(2)> [27, 35, 51] ++ [0]
[27, 35, 51, 0]

iex(3)> inspect [27, 35, 51], charlists: :as_lists

Also see this post to the Elixir-Lang mailing list for a bit more on the reasoning behind this design choice:

5. Which functions are allowed in guards?

The Erlang VM only allows a limited set of expressions in guards. For an up to date list please read Expressions in guard clauses in the Elixir Website.

6. Where's List.append?

For a few good reasons, Elixir doesn't include an append function in the List module. In no particular order:

  • Due to the underlying implementation of Elixir's lists, appending to a list is an O(n) operation. It's always much more efficient to prepend to the list and reverse the list. Prepending is O(1).

  • If you need to append to a list there's the ++ operator available. Since that's implemented in Erlang and Elixir avoids re-implementing things in Erlang unless it's necessary, we suggest people use the ++ to append to a list e. g. l ++ [new_list]

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.