elixir, the hipster language
(hands-on session)

philip giuliani, daniel morandini, andrea janes
topics
this is how we will spend our/your time:
conclusion and finish the buffet!
installation
practice
time!
introduction
break!
technical/
philosophical part
people from industry arrive
elixir?
Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine (BEAM)*.
Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications.
Elixir also provides a productive tooling and an extensible design.
* https://en.wikipedia.org/wiki/Elixir_(programming_language)
hipster?

so... let's start
- go to http://elixir-lang.github.io/install.html
- follow the instructions
- congratulations!
do you use an editor?
- one option is https://code.visualstudio.com
- together with the extension for elixir: https://marketplace.visualstudio.com/items?itemName=mjmcloug.vscode-elixir
elixir basics
- we look into
- chapter 2
- chapter 13

task 1
- open your command line
- create a new project with "mix new helloworld"
- open the project in your editor
task 2
- open your command line
- create a new project with "mix new helloworld"
- open the project in your editor
- let's have a look at the structure
task 3
- in the command line, change to the project folder
- execute "iex -S mix", this
- compiles the project
- runs the interactive shell
- and loads the project into the shell so that we can test it
- enter "Helloworld.hello"
- you should get ":hello"
task 4
- define a new function like this:
- in your command line, within iex
- run "recompile()"
- check that there are no errors
- run "Helloworld.sum1"
- if you enter two integers, it works
- what if you enter "4.2"?
- what if you enter "abc"?
def sum1() do
{a, _} = IO.gets("enter a: ") |> Integer.parse
{b, _} = IO.gets("enter b: ") |> Integer.parse
a+b
end
task 5
- define a new function like this:
def sum2() do
IO.gets("enter a: ") |> Integer.parse |> handle_result
end
def handle_result({number, "\n"}) do
IO.puts "You entered #{number}"
end
def handle_result({_, whaaat}) do
text = String.replace_trailing(whaaat, "\n", "")
IO.puts "You did not enter an integer. What is #{text}?"
end
task 5
- in your command line, within iex
- run "recompile()"
- check that there are no errors
- run "Helloworld.sum2"
- if you enter an integer, it works
- what if you enter "4.2"?
- what if you enter "abc"?
task 6
- define a new function like this:
def sum3() do
result = IO.gets("enter a: ") |> Integer.parse
case result do
:error -> "You entered a string!"
{a, "\n"} when a > 100 -> "You entered a number higher than 100"
{_, "\n"} -> "OK"
{_, _} -> "Incorrect input!"
end
end
task 6
- in your command line, within iex
- run "recompile()"
- check that there are no errors
- run "Helloworld.sum3"
- if you enter an integer, it works
- what if you enter "4.2"?
- what if you enter "abc"?
task 7
- write a function that lets you enter two numbers and an operation character ("+" or "-")
- output the correct result
- use pattern matching instead of "if"
task 8
- Read the Enum.map and Enum.filter documentation of Elixir
- Define
- fahrenheit_temps = [32, 68, 100, 212, 50, 75]
- max_celsius = 30
Write the code to first convert to Celcius ((fahrenheit - 32) * 5 / 9) and then filter by max_celcius
Elixir hands on
By Andrea Janes
Elixir hands on
- 105