Erlang crash course CiA Oslo 2012
-
Upload
reidar-sollid -
Category
Technology
-
view
300 -
download
3
description
Transcript of Erlang crash course CiA Oslo 2012
Crash course in Erlang Erlang in 15 minutes
Baksia CiA2012 Erlang
Page 1
, 09.02.12
• The world is concurrent • Things in the world don't share data • Things communicate with messages • Things fail
- Joe Armstrong
Baksia CiA2012 Erlang
Page 2
, 09.02.12
" Erlang
• Created and maintained by Ericsson (now open source) • Functional, single assignment, strict evaluation, dynamic
typing • Actor model, concurrent oriented, fault tolerant, soft-real-
time • Light weight processes that communicate using message
passing (an Erlang process is more light weight than a Java thread)
• Erlang started life as a modified prolog • Erlang shell, escript and compiled .beam bytecode
Baksia CiA2012 Erlang
Page 3
, 09.02.12
" What is Erlang
• An atom is a global constant starting with lower case • A tuple is an ordered set of elements • Your Java or C# class would be a tuple with an atom
identifier
Baksia CiA2012 Erlang
Page 4
, 09.02.12
" Atoms and tuples
• Erlang is designed for massive concurrency. Erlang processes are light-weight (grow and shrink dynamically) with small memory footprint, fast to create and terminate and the scheduling overhead is low.
• A process is created by calling spawn • Spawn returns a process Id PID in which you can send
messages to with the bang ! sign
Baksia CiA2012 Erlang
Page 5
, 09.02.12
" Erlang processes
Baksia CiA2012 Erlang
Page 6
, 09.02.12
" The *Real* Erlang "Hello, World!"
h"p://egarson.blogspot.com/2008/03/real-‐erlang-‐hello-‐world.html
Baksia CiA2012 Erlang
Page 7
, 09.02.12
" Pattern matching
Baksia CiA2012 Erlang
Page 8
, 09.02.12
" Variables and pattern matching
Baksia CiA2012 Erlang
Page 9
, 09.02.12
" Actors and pattern matching
Baksia CiA2012 Erlang
Page 10
, 09.02.12
" Loops
Baksia CiA2012 Erlang
Page 11
, 09.02.12
" No while or for loops ?
Baksia CiA2012 Erlang
Page 12
, 09.02.12
" Tail recursion
Baksia CiA2012 Erlang
Page 13
, 09.02.12
" Tail optimized recursion
tail recursion as seen here is not making the memory grow because when the virtual machine sees a funcAon calling itself in a tail posiAon (the last expression to be evaluated in a funcAon), it eliminates the current stack frame.
Baksia CiA2012 Erlang
Page 14
, 09.02.12
" Changes
• BIFs are functions that are part of the Erlang language • BIFs usually do tasks that are impossible to do in Erlang
• list_to_tuple([22,cat,”text”]). • spawn(fun() -> my_fun(“Hello”) end).
Baksia CiA2012 Erlang
Page 15
, 09.02.12
" BIF Built In Functions
• Great site • http://learnyousomeerlang.com/
Baksia CiA2012 Erlang
Page 16
, 09.02.12
" Learn you some Erlang
Baksia CiA2012 Erlang
Page 17
, 09.02.12
CiA 2012 -‐ Bridging the gaps 8 februar 17:30 – 20:30