-
Notifications
You must be signed in to change notification settings - Fork 3.4k
In short:
- data processing
- network related tasks: from plain sockets to web servers and frameworks
- writing reliable, distributed, and highly available software.
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? [stackoverflow.com]
- Go, F# and Erlang -- implementation of matrix multiplication and prime number test in each of the three languages [paper]
iex -S mix
inside your project's directory.
There's a very nice module [erlang-history] that does the trick for both elixir and erlang shells.
For example:
iex(1)> [27, 35, 51]
'\e#3'
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], char_lists: false
"[27,35,51]"
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.
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]