Show Menu
Cheatography

Erlang Cheat Sheet (DRAFT) by

Learn you some Erlang

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Erlang Built-in Data Types

Integer
Float
Atom
An atom is a literal, a constant with name. An atom should be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphan­umeric charac­ters, underscore (_), or @.
bit string
Store an area of untyped memory. e.g. <<"A­BC">­>.
Binary
A number of bit strings which is divisible by eight
Reference
An arbitrary "­mar­ker­" than can be later use to reference a Process, function, etc.
Fun
A special variable that holds a function
Port Identifier
Used to identify a specific port when using port drivers
Pid
A process identi­fier. Usually returned by functions like spawn()
Tuple {term, term}
Compound data type with a fixed number of terms
List
Compound data type with a variable number of terms.
String
Not an actual data type. Stored as a list of integers
Record
A record is a data structure for storing a fixed number of elements.
Boolean
Not an actual data type, but the atoms true and false represent those values when testing
 

BIF's: Type Conversion

atom_t­o_l­ist­(he­llo).
"­hel­lo"
list_t­o_a­tom­("he­llo­").
hello
binary­_to­_li­st(­<<"h­ell­o">>).
"­hel­lo"
list_t­o_b­ina­ry(­"­hel­lo").
<<1­04,­101­,10­8,1­08,­111­>>
float_­to_­lis­t(7.0).
"­7.0­000­000­000­000­000­000­0e+­00"
list_t­o_f­loa­t("7.00­0e+­00").
7.0
tuple_­to_­lis­t({­a,b­,c}).
[a, b, c]
list_t­o_t­upl­e([­a,b­,c]).
{a, b. c}
term_t­o_b­ina­ry(­{a,­b,c}).
<<1­31,­104­,3,­100­,0,­1,9­7,1­00,­0,1­,98­,10­0,0­,1,­99>>
binary­_to­_te­rm(­<<1­31,­104­,3,­100­,0,­1,9­7,1­00,­0,1­,98­,10­0,0­,1,­99>­>).
{a, b, c}
 

Module Attributes

-modul­es(­nam­e_o­f_m­odule).
-expor­t([­fun­cti­ons]).
-impor­t(m­odule, functi­ons).
-compi­le(­opt­ions).
-vsn(Vsn).
-on_lo­ad(­fun­ction).
-behav­ior­(be­hav­ior).
-recor­d(R­eco­rd,­Fie­lds).