My Kindle informs me that I’m still only at 61% of the Elixir book. I forgot that reading a book about a new language involves some work – and you can’t do all of it lying at the beach, if you know what I mean. Anyway, as an appetizer here’s a tiny bit of Elixir for you.
Disclaimer: If you haven’t seen any Elixir up to now at all, this is _not_ the place to start. If you know the basics of the syntax and want to use Elixir for some scripting, read on. Also, all the credit goes to Dave Thomas.
Scripting is especially easy with Elixir because of the Elixorians’ favorite operator:
|>, the Elixir pipe. It works just like the pipe in your shell – it takes the output of the function to its left and feeds it as the first argument to the function to its right.
That comes in handy, because that simple command-line utility you want to write will probably look something like this:
parse_options |> process |> do_magic_things |> print_results
You just need Erlang and Elixir installed. You Homebrew users can happily type
$ brew install erlang-r16 elixir
Everybody else, go here.
Creating a scaffold application with mix
mix is basically Elixir’s
bundler. You use it to bootstrap and build your projects, create tasks, install dependencies, and run your tests.
Let’s create a new project:
$ mix new example
This will create a project scaffold in
./example/, complete with a README, a
lib/ and a
test/ directory and a configuration file named
mix.exs . Didn’t hurt a bit, did it?