One of the more exciting new functional languages of the last couple of years is a marriage of Erlang and Ruby called Elixir. Besides adding an arguably better syntax with which to program the Erlang VM (also known as the BEAM VM), Elixir adds meta-programming, addresses issues Erlang had with dealing with Unicode strings, and adds few other nice touches. It’s nice icing on the Erlang cake. Joe Armstrong, the creator of Erlang, has gone on record as endorsing Elixir. I leave it to those who are interested in reading Mr. Armstrong’s comments to read for themselves; tl; dr he likes Elixir just like he likes Erlang.

So I’ve been wanting to play with Elixir for a while and when I want to play with a new language, I often configure a quick command prompt set up with the proper development environment. It’s halfway between creating a new VM and not doing anything special. So if others care to build an elixir command prompt, here are the steps. Note that you can stop before installing Elixir and have a great Erlang environment to play around with.

1.) Install Erlang. You can download a nice Windows installer package for Erlang from Erlang Solutions.

2.) Once erlang is installed, you’ll want to grab the prebuilt zip of Elixir from the Elixir GitHub repository.

3.) Create a powershell script to configure the environment. Here’s mine:

Set-Variable -Name elixirBase -option Readonly -value "C:/dev/elixir_0.12.4" Set-Variable -Name erlangBase -option Readonly -value "C:/Program Files/erl5.10.2" Set-Variable -Name gitPath -option Readonly -value "c:/program files (x86)/git" $env:Path = "$erlangBase/bin;$elixirBase/bin;$gitPath/bin;"

Set-Variable is the Powershell analog of setting an environment variable. $env:Path is the actual Path environment variable in this case. Since the environment will only apply for the duration of the Powershell session, I simply replace the existing Path with one set up specifically for the Elixir/Erlang combo. I named the file ElixirSetup.ps1; it’s convention for Powershell scripts to have a ps1 extension. NB: These paths are on my machine and they’re for a slightly older version of Erlang (as of this writing current version installs to elr5.10.4).

Basically if I’m going to do a command prompt on Windows, Powershell is the way to go. It remedies countless failings of the old cmd shell.

4.) Create a new shortcut with the following command line:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -File C:\Users\Onorio_Development\Documents\WindowsPowerShell\ElixirSetup.ps1

Obviously you’ll want to replace these values with the correct values for your particular machine.

Once you get the shortcut set up and going, there are a few things to test. You can run the Erlang REPL by typing erl at the command prompt. You can test the Elixir REPL by typing iex.bat at the command prompt. You have to type the entire name (with the .bat extension) due to there being an iex alias present in Powershell.

Elixir includes a nice little project management tool called mix which was inspired by Clojure’s Leiningen. Mix basically lets you create a small skeleton of an Elixir project complete with a .gitignore file and a README.md as well as a skeleton unit test.

I hope others will consider this an invitation to start playing with Elixir and learning more about both Elixir and Erlang.

EDIT: One annoyance that I discovered after I wrote this post is that the native Powershell terminal doesn’t support ANSI escape sequences. IEx uses ANSI escape sequences and this is a real annoyance. So I did some digging and found that ConEmu has nice support for ANSI and it remedies the issue with IEx very nicely. There are other ways of getting support for the ANSI escape sequences as well but this is a nice robust remedy for the problem.