Erlang Flashcards
erlang og need
telecom systems where reliability, responsiveness, scalability, and constant availability were needed
nature of erlang programs
immutable data, pattern matching, functional programming, garbage collector
sequential subset of erlang lang supports
eager evaluation, single assignment, dynamic typing
normal erlang application built out of
thousands of small erlang programs
BEAM
virtual machine at core of erlang
part of run time system
.beam file extension
Erlang run time system (ERTS) compiles
erlang source code into bytecode which runs on BEAM
ERTS designed for systems with these traits:
distributed, fault tolerant, soft real time, highly available non stop apps, hot swapping
what makes erlang processes “living” objects
data encapsulation, message passing and capable of changing behavior during runtime (hot swapping)
thread of execution
process
how does erlang communicate
asynch signaling
most commonly used signal
message
other common signals
exit, link, unlink, monitor, demonitor
basic unit of concurrency
process
process
lightweight thread of execution that runs independently and communicates with other processes through message passing
how are processes created
spawn function -> takes function as an argument and returns process identifier (pid)
what is a program a call to
call to an initial function
how are processes scheduled
virtual machine (vm)
erlang: let it crash or let it fail
let it fail -> less code devoted to defensive programming
design philosophy
systems -> expect failure to happen, build supervisor structure to monitor executions, detect failures, and restart failed processes
variables
sequence of characters, must begin with uppercase letter
are variables single assignment
yes, value cannot be changed once assigned
atoms
sequence of characters, must begin with lowercase
functions
named sequences of expressions to be evaluated
modules
primary mechanism for organizing erlang code -> contain func defs
basic data types
atom, int, float, binary, pid, port, fun
structured types
list: dynamic mixed collection []
tuple: fixed-length mixed collection {}
pattern matching
used in function parameter binding
guards
used to partially define function clauses
io:format(“~s~p~n”[“age: “, 45]).
what does this do
~n -> newline
~p -> numeric data
~s -> string data
module consists of
sequence of attributes and function declarations
what do modules get compiled into
nameoffile.beam
function declaration
sequence of function clauses separated by semicolons and terminated by period
what does a function clause consist of
head and body separated by ->
clause head
func name, argument list, optional guard sequence beg with keyword when
sequential scope
variables are accessible after they are bound
nested scope
inner expressions dont leak variables to outer ones
t/f: no global variables
true, everything is local to the func, mod, or process
t/f: processes can share variables
false, its all local to process scope
pattern matching scope
case, receive, if expressions -> vars are bound to one branch only