I've recently discovered Elixir, a dynamic programming language for the Erlang virtual machine. As such, it can easily share code with Erlang. All of that Erlang code out there is available for use in Elixir. And anything we write in Elixir can be used by folks writing in Erlang. It's analogous to Groovy and Java in that regard.
Elixir needs a newer version of Erlang than my operating system provides, so I started by installing esl-erlang from a different repository. Having done that, I installed the latest Elixir from source.
$ git clone https://github.com/elixir-lang/elixir.git ... $ cd elixir $ make ... $ make test ...
Okay, without doing the make install, let's try out the REPL in place!
$ bin/iex Erlang R16B01 (erts-5.10.2) [source-bdf5300] [64-bit] [smp:2:2] [async- threads:10] [hipe] [kernel-poll:false] Interactive Elixir (0.10.3-dev) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> 2 + 2 4 iex(2)> 10/2 5.0 iex(3)> div 10, 2 5
Cool beans! In practice, though, I rarely use a REPL. I want to teach Emacs and Vim about Elixir. I have Emacs 24 configured to use MELPA already, so installing elixir-mode is as easy as
M-x package-install RET elixir-mode RET
For Vim, I use pathogen, so it's just
$ cd .vim/bundle $ git clone https://github.com/elixir-lang/vim-elixir.git ...
Now I'm ready to write some code! Here's my crack at hello world in elixir
#!/usr/bin/env elixir greet = fn s -> IO.puts "Hello, #{s}!" end if length(System.argv) == 0 do greet.("World") else Enum.each(System.argv, greet) end
With no arguments, this prints hello world
$ ./hello.ex Hello, World!
But with arguments, it says hello to each one
$ ./hello.ex Hank Dean Brock Hello, Hank! Hello, Dean! Hello, Brock!
But if-else? There must a more elixiry way to do that. I think I have a lot to learn. Back to the docs!
Recent Comments