class: center, middle
Pre-alpha Kottans courses
class: center,middle
class: center,middle
- Erlang module is a group of connected functions in common namespace
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- the only required attribute is module name (
-module(Module)
)
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- the only required attribute is module name (
-module(Module)
) - can export functions (
-export(Functions)
)
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- the only required attribute is module name (
-module(Module)
) - can export functions (
-export(Functions)
) - can import functions (
-import(Module, Functions)
)
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- the only required attribute is module name (
-module(Module)
) - can export functions (
-export(Functions)
) - can import functions (
-import(Module, Functions)
) - can receive options for compiler (
-compile(Options)
)
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- the only required attribute is module name (
-module(Module)
) - can export functions (
-export(Functions)
) - can import functions (
-import(Module, Functions)
) - can receive options for compiler (
-compile(Options)
) - can contain version (
-vsn(Version)
)
- Erlang module is a group of connected functions in common namespace
- can contain attributes
- the only required attribute is module name (
-module(Module)
) - can export functions (
-export(Functions)
) - can import functions (
-import(Module, Functions)
) - can receive options for compiler (
-compile(Options)
) - can contain version (
-vsn(Version)
) - can execute function on loading (
-on_load(Function)
)
In general modules can contain:
- function declarations
In general modules can contain:
- function declarations
- type declarations
In general modules can contain:
- function declarations
- type declarations
- record declarations
In general modules can contain:
- function declarations
- type declarations
- record declarations
- macros
In general modules can contain:
- function declarations
- type declarations
- record declarations
- macros
- another attributes
class: center, middle
- is a sequence of function clauses separated by
;
- is a sequence of function clauses separated by
;
- consists of clause head and clause body, separated by
->
- is a sequence of function clauses separated by
;
- consists of clause head and clause body, separated by
->
- head consists of name, argument list and optional guard
- is a sequence of function clauses separated by
;
- consists of clause head and clause body, separated by
->
- head consists of name, argument list and optional guard
- body consists of sequence of expressions separated by
,
- is a sequence of function clauses separated by
;
- consists of clause head and clause body, separated by
->
- head consists of name, argument list and optional guard
- body consists of sequence of expressions separated by
,
fact(N) when N>0 -> % first clause head (name atom, args list + guard)
N * fact(N-1); % first clause body
fact(0) -> % second clause head
1. % second clause body and end of function
class: center,middle
Erlang allows developer to define user types. This definitions can be used internally for function specifications, externally (known as remote types) and in records.
Erlang allows developer to define user types. This definitions can be used internally for function specifications, externally (known as remote types) and in records.
- has to be derived from predefined types
Erlang allows developer to define user types. This definitions can be used internally for function specifications, externally (known as remote types) and in records.
- has to be derived from predefined types
- has to have unique name if exported (inside module)
Erlang allows developer to define user types. This definitions can be used internally for function specifications, externally (known as remote types) and in records.
- has to be derived from predefined types
- has to have unique name if exported (inside module)
- can be used for static type analyzer tool like Dialyzer or for documentation
Erlang allows developer to define user types. This definitions can be used internally for function specifications, externally (known as remote types) and in records.
- has to be derived from predefined types
- has to have unique name if exported (inside module)
- can be used for static type analyzer tool like Dialyzer or for documentation
-module(mod).
-type orddict(Key, Val) :: [{Key, Val}]. % type with name orddict and args Key and Val
-export_type([orddict/2]). % list with types and their arity
% example of usage in record
-record(ordrec, {field1 :: orddict()}). % record can contain field1 which is orddict
% example of usage in specification
-spec fact(N :: integer()) -> integer(). % N argument of function fact can only be integer and result is integer too
class: center,middle
As you remember, record is syntax sugar for tuple with named fields.
-record(person, {name = "", phone = [], address}). % definition of record in module
-record(name, {first = "Robert", last = "Ericsson"}).
-record(person, {name = #name{}, phone}). % example of nested record
class: center,middle
Macro is an special instruction for compiler. They can be user-defined or predefined.
-define(Const, Replacement). % Const will be replaced in time of compiling with Replacement value
-define(TIMEOUT, 200). % example of above
-define(MACRO1(X, Y), {a, X, b, Y}). % example of parameters in macros
Macro is an special instruction for compiler. They can be user-defined or predefined.
?MODULE
- atom name of current module
Macro is an special instruction for compiler. They can be user-defined or predefined.
?MODULE
- atom name of current module?MODULE_STRING
- string name of current module
Macro is an special instruction for compiler. They can be user-defined or predefined.
?MODULE
- atom name of current module?MODULE_STRING
- string name of current module?FILE
- file name of current module
Macro is an special instruction for compiler. They can be user-defined or predefined.
?MODULE
- atom name of current module?MODULE_STRING
- string name of current module?FILE
- file name of current module?LINE
- current line number
Macro is an special instruction for compiler. They can be user-defined or predefined.
?MODULE
- atom name of current module?MODULE_STRING
- string name of current module?FILE
- file name of current module?LINE
- current line number?MACHINE
- virtual machine name,BEAM
class: center,middle
class: center,middle
case Expr of
Pattern1 [when GuardSeq1] ->
Body1;
...;
PatternN [when GuardSeqN] ->
BodyN
end
class: center,middle
if
GuardSeq1 ->
Body1;
...;
GuardSeqN ->
BodyN;
true -> % works as else branch
Result
end
class: center,middle
try Exprs of
Pattern1 [when GuardSeq1] ->
Body1;
...;
PatternN [when GuardSeqN] ->
BodyN
catch
[Class1:]ExceptionPattern1 [when ExceptionGuardSeq1] ->
ExceptionBody1;
...;
[ClassN:]ExceptionPatternN [when ExceptionGuardSeqN] ->
ExceptionBodyN
after
AfterBody
end
class: center,middle
receive
Pattern1 [when GuardSeq1] ->
Body1;
...;
PatternN [when GuardSeqN] ->
BodyN
after
ExprT -> % ExprT :: integer(), timeout for receive loop
BodyT
end
class: center,middle
==
- equal to
==
- equal to/=
- not equal to
==
- equal to/=
- not equal to=<
- less than
==
- equal to/=
- not equal to=<
- less than or equal to<
- less than
==
- equal to/=
- not equal to=<
- less than or equal to<
- less than>=
- greater than or equal to
==
- equal to/=
- not equal to=<
- less than or equal to<
- less than>=
- greater than or equal to>
- greater than
==
- equal to/=
- not equal to=<
- less than or equal to<
- less than>=
- greater than or equal to>
- greater than=:=
- exactly equal to
==
- equal to/=
- not equal to=<
- less than or equal to<
- less than>=
- greater than or equal to>
- greater than=:=
- exactly equal to=/=
- exactly not equal to
==
- equal to/=
- not equal to=<
- less than or equal to<
- less than>=
- greater than or equal to>
- greater than=:=
- exactly equal to=/=
- exactly not equal to- types comparison order:
number < atom < reference < fun < port < pid < tuple < list < bit string
class: center,middle
class: center,middle