際際滷s used for introducing and training Erlang/Elixir at the Webilea Hands-On event (http://www.meetup.com/webilea/events/170710572/).
Following topics are more or less covered:
1. very short introduction to the language
2. people try some Erlang over at http://tryerlang.org
3. 'Let it crash'
4. Playing with spawn/link/monitor
5. quick intro to gen_sever and supervisor behaviour
1 of 22
Downloaded 11 times
More Related Content
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
1. Erlang
Elixir Webilea Hands-On Session
at Obst & Gem端se, 19.3.2014
By Andr辿 Graf
@der_graf / @erlio_basel
2. Preliminaries
Erlang and Elixir Programs are compiled for
the BEAM*
Similar datatypes and runtime behavior
Different syntax, language features, stdlib
*Bogdan/Bj旦rn's Erlang Abstract Machine
3. 1986
Erlang has been developed
by Ericsson, for building
highly available telco
systems
Massively concurrent
server systems
Server systems
that run forever
Hot-Code
Upgrades
Inherently parallel
problem domain
High availability
through redundancy
Debugging
Live Systems
4. Functional
Compiled
Dynamically typed
VM & Shell
Very lightweight processes
Processes don't share state
Message Passing Concurrency
Process Supervision (Let it crash)
Built-in Distribution
Hot-Code Upgrades
5. Erlang OTP
Architecture Patterns
Middlewares
Libraries
Tools
You could use Erlang witout OTP (nobody does)
OTP is included in the Erlang distribution
OTP is closely tied to the Erlang VM
6. 1998
Erlang has been
opensourced and other
companies started using it.
Ericsson went for C++
Massively concurrent
server systems
Server systems
that run forever
Hot-Code
Upgrades
Inherently parallel
problem domain
High availability
through redundancy
Debugging
Live Systems
10. Functional
Compiled
Dynamically typed
VM & Shell
Very lightweight processes
Processes don't share state
Message Passing Concurrency
Process Supervision (Let it crash)
Built-in Distribution
Hot-Code Upgrades
11. Erlang vs. Elixir
very subjective
+ Elixir has a more familiar Syntax.
+ Elixir fixes several language design mistakes
from the past. *
+ Elixir will bring more people to the Beam.
+ Elixir has better meta-programming support.
- Elixir has (currently) no own OTP framework.
> killer for production use.
* http://joearms.github.io/2013/05/31/a-week-with-elixir.html
12. Erlang Hands-On
1. Installation Party
2. Language introduction http://www.tryerlang.org/
3. My first Erlang module
4. My first Erlang process
5. Let it crash
6. OTP behaviours gen_server / supervisor
7. Recap / Discussion
14. My first Erlang Module
Module-Name == Filename.erl
e.g. my_first_module.erl
-module(my_first_module).
-export([my_first_function/1]).
% this is a comment for my first function
% this is another line of the comment
my_first_function(Param) ->
io:format(wow my first function got called with param: ~p~n, [Param]).
1. Compile with erlc my_first_module.erl
2. Start Erlang shell with: erl
3. Call function my_first_module:my_first_function(hello world).
15. My first Erlang Process
-module(my_first_module).
-export([my_first_function/0,
start_my_first_process/0]).
my_first_function() ->
receive
Msg ->
io:format(wow my first process got a msg: ~p~n, [Msg])
end.
start_my_first_process() ->
spawn(?MODULE, my_first_function, []).
1. Compile with erlc my_first_module.erl
or if you are inside the shell with:
c(my_first_module).
l(my_first_module).
2. Start your first process:
Pid = my_first_module:start_my_first_process().
3. Send your first message:
Pid ! yeah_this_is_my_first_message.
4. How can you reuse the Process???
16. Let it Crash
-module(my_first_module).
-export([my_first_function/0,
start_my_first_process/0]).
my_first_function() ->
receive
Msg ->
dispatch_my_msg(Msg),
my_first_function() %% yay, recursion!
end.
start_my_first_process() ->
spawn(?MODULE, my_first_function, []).
dispatch_my_msg({hello, world}) ->
io:format(what a great hello world~n);
dispatch_my_msg({A, B}) ->
io:format(tuple with ~p and ~p~n, [A,B]).
1. kinda stupid dispatcher, right???
18. OTP Behaviours
gen_server
Generic way to write servers in Erlang OTP Style
Supervisor
A Supervisor that supervises other OTP compliant
processes (e.g. gen_servers, gen_fsms)