Elixir
With the elixir-lang 1.0.0 release approaching, I thought I’d jump in and get better acquainted with the language. First, a huge thanks to Jose and everyone involved with elixir. As much for creating a great new language, but also for giving me more motivation to read my Programming Erlang book.
Here are a few first things in learning the language…
Interactive Elixir: iex
Having an interactive mode is incredible. I’ve so use to irb (interactive ruby) for so long, I was thrilled to see this available for elixir.
The first struggle was trying to quit iex. I was so used to
ctrl-d
working, I was quite surprised when it didn’t work. Instead, to quit
iex it’s ctrl-g q <enter>
. I’m guessing
there’s more to that than meets the eye.
help within iex
This is awesome, the language documentation is available within iex.
iex(10)> h is_boolean/1
def is_boolean(term)
Returns true if term is either the atom true or the atom false (i.e. a
boolean); otherwise returns false.
Allowed in guard tests. Inlined by the compiler.
The h is_boolean/1
means: ‘help on function is_boolean
with arity 1.
The help has tab completion too…
iex(27)> h is_<tab>
is_atom/1 is_binary/1 is_bitstring/1 is_boolean/1
is_float/1 is_function/1 is_function/2 is_integer/1
is_list/1 is_map/1 is_number/1 is_pid/1
is_port/1 is_reference/1 is_tuple/1
iex(27)> h is_<cursor>
The arity isn’t required for getting help. And, when not given for something
that has multiple signatures (or whatever elixir calls them), will show
all matches. E.g., h is_function
will display help for both
the arity 1 and arity 2 versions.
Still Learning
I’m just getting started, but it’s fun to learn a language that gives you approachable tools, like iex, to play with. Next up is to figure out why this works, and why I should know why it works…
iex(43)> [1, 2, 3] |> Enum.map(&(&1 * &1))
[1, 4, 9]
iex(44)>
Check out Elixir. If you want high level information, check out the Elixir Conf videos.