class: center,middle
Pre-alpha Kottans courses
class: center,middle
class: center,middle
$ apt-get install erlang
$ yum install erlang
$ brew install erlang
$ port install erlang
$ cd /usr/ports/lang/erlang && make install clean
$ pkg_add -rv erlang
Just download Erlang binary from this page, install it and add it to PATH
variable.
class: middle,center
It's simple. Just type erl
and receive:
$ erl
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V6.4 (abort with ^G)
1>
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime System
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source64-bit
- appears in case of 64-bit architecture and addshalfword
if uses half world heap
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source64-bit
- appears in case of 64-bit architecture and addshalfword
if uses half world heapsmp:4:4
- appears on symmetric multiprocessor systems, first number shows total cores, second - online cores
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source64-bit
- appears in case of 64-bit architecture and addshalfword
if uses half world heapsmp:4:4
- appears on symmetric multiprocessor systems, first number shows total cores, second - online coresasync-threads:10
- appears in case if Erlang uses threads, number means size of thread pool
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source64-bit
- appears in case of 64-bit architecture and addshalfword
if uses half world heapsmp:4:4
- appears on symmetric multiprocessor systems, first number shows total cores, second - online coresasync-threads:10
- appears in case if Erlang uses threads, number means size of thread poolhipe
- appears in case of usage HiPE. HiPE means High Performance Erlang, efficient Erlang compiler integrated into OTP
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source64-bit
- appears in case of 64-bit architecture and addshalfword
if uses half world heapsmp:4:4
- appears on symmetric multiprocessor systems, first number shows total cores, second - online coresasync-threads:10
- appears in case if Erlang uses threads, number means size of thread poolhipe
- appears in case of usage HiPE. HiPE means High Performance Erlang, efficient Erlang compiler integrated into OTPkernel-poll:false
- is Kernel Poll turned on or off. Kernel Poll used to improve performance if you have a number (hundreds or more) of simulanteus network connections
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
erts
- Erlang Runtime Systemsource
- hasERLANG_GIT_VERSION
variable if Erlang was built from git source64-bit
- appears in case of 64-bit architecture and addshalfword
if uses half world heapsmp:4:4
- appears on symmetric multiprocessor systems, first number shows total cores, second - online coresasync-threads:10
- appears in case if Erlang uses threads, number means size of thread poolhipe
- appears in case of usage HiPE. HiPE means High Performance Erlang, efficient Erlang compiler integrated into OTPkernel-poll:false
- is Kernel Poll turned on or off. Kernel Poll used to improve performance if you have a number (hundreds or more) of simulanteus network connectionsdtrace
- support of DTrace dynamic tracing framework for BEAM
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool+d
- generate only core dump without crash dump. Crash dump destroys process heaps so core dump became useless
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool+d
- generate only core dump without crash dump. Crash dump destroys process heaps so core dump became useless+L
- don't load information about source file names and line numbers. Exceptions will become useless, but used memory amount will became less
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool+d
- generate only core dump without crash dump. Crash dump destroys process heaps so core dump became useless+L
- don't load information about source file names and line numbers. Exceptions will become useless, but used memory amount will became less+pc Range
- range of characters used for heuristic string detection. Can belatin1
orunicode
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool+d
- generate only core dump without crash dump. Crash dump destroys process heaps so core dump became useless+L
- don't load information about source file names and line numbers. Exceptions will become useless, but used memory amount will became less+pc Range
- range of characters used for heuristic string detection. Can belatin1
orunicode
+R ReleaseNumber
- compatibility mode
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool+d
- generate only core dump without crash dump. Crash dump destroys process heaps so core dump became useless+L
- don't load information about source file names and line numbers. Exceptions will become useless, but used memory amount will became less+pc Range
- range of characters used for heuristic string detection. Can belatin1
orunicode
+R ReleaseNumber
- compatibility mode+V
- print emulator version
If you are using emulator flags they influence the way Erlang virtual machine works.
+A size
- number of threads in async thread pool+d
- generate only core dump without crash dump. Crash dump destroys process heaps so core dump became useless+L
- don't load information about source file names and line numbers. Exceptions will become useless, but used memory amount will became less+pc Range
- range of characters used for heuristic string detection. Can belatin1
orunicode
+R ReleaseNumber
- compatibility mode+V
- print emulator version+v
- become verbose
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node-compile Mod1 Mod2...
- compile passed modules and terminate
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node-compile Mod1 Mod2...
- compile passed modules and terminate-setcookie Cookie
- set security cookie for creating cluster
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node-compile Mod1 Mod2...
- compile passed modules and terminate-setcookie Cookie
- set security cookie for creating cluster-detached
- start Erlang node as a daemon
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node-compile Mod1 Mod2...
- compile passed modules and terminate-setcookie Cookie
- set security cookie for creating cluster-detached
- start Erlang node as a daemon-hosts Hosts
- provide list of IP addresses of Erlang nodes, DNS names are not allowed
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node-compile Mod1 Mod2...
- compile passed modules and terminate-setcookie Cookie
- set security cookie for creating cluster-detached
- start Erlang node as a daemon-hosts Hosts
- provide list of IP addresses of Erlang nodes, DNS names are not allowed-sname Name
- short name of Erlang node
Switches are very useful to set up initial Erlang node params.
-async_shell_start
- start shell in parallel with Erlang node-compile Mod1 Mod2...
- compile passed modules and terminate-setcookie Cookie
- set security cookie for creating cluster-detached
- start Erlang node as a daemon-hosts Hosts
- provide list of IP addresses of Erlang nodes, DNS names are not allowed-sname Name
- short name of Erlang node-version
- the same as emulator flag+V
class: center,middle
You can use several sources to read Erlang documentation:
erl -man module_name
- Erlang man pages
You can use several sources to read Erlang documentation:
erl -man module_name
- Erlang man pages- http://www.erlang.org/doc/
You can use several sources to read Erlang documentation:
erl -man module_name
- Erlang man pages- http://www.erlang.org/doc/
- Dash Mac OS X application (https://kapeli.com/dash)
You can use several sources to read Erlang documentation:
erl -man module_name
- Erlang man pages- http://www.erlang.org/doc/
- Dash Mac OS X application (https://kapeli.com/dash)
- http://erldocs.com/
class: middle,center
- Erlang shell is not REPL at all. It isn't as in LISP
(loop (print (eval (read))))
- Erlang shell is not REPL at all. It isn't as in LISP
(loop (print (eval (read))))
- shell is just another Erlang process
- Erlang shell is not REPL at all. It isn't as in LISP
(loop (print (eval (read))))
- shell is just another Erlang process
- it captures
STDOUT
andSTDIN
and redirects them to process, in this case - shell
- Erlang shell is not REPL at all. It isn't as in LISP
(loop (print (eval (read))))
- shell is just another Erlang process
- it captures
STDOUT
andSTDIN
and redirects them to process, in this case - shell - multiple shells can be run in one emulator
- Erlang shell is not REPL at all. It isn't as in LISP
(loop (print (eval (read))))
- shell is just another Erlang process
- it captures
STDOUT
andSTDIN
and redirects them to process, in this case - shell - multiple shells can be run in one emulator
- even remote!
Erlang shell takes code as regular Erlang code except several keywords like module
or export
.
Please try next code in your local Erlang shell (ignore strings after percent sign):
1> 4 + 3. % 7
2> A = 5,
2> B = A,
2> A + B. % 10
Erlang shell takes code as regular Erlang code except several keywords like module
or export
.
Please try next code in your local Erlang shell (ignore strings after percent sign):
1> 4 + 3. % 7
2> A = 5,
2> B = A,
2> A + B. % 10
As you can see, Erlang executes code as it is, .
(dot) is delimiter which gives instruction to execute, ,
is instruction separator (only last line of code block returns result). Line counter at prompt is not line counter but more like instruction counter.
class: middle,center
--- # ~~Ctrl-Z~~ Ctrl-G!This hotkey is used to achieve low-level CLI of Erlang shell.
After Ctrl-G
has been pressed, you'll receive invitation like this:
User switch command
-->
This hotkey is used to achieve low-level CLI of Erlang shell.
After Ctrl-G
has been pressed, you'll receive invitation like this:
User switch command
--> h
c [nn] - connect to job
i [nn] - interrupt job
k [nn] - kill job
j - list all jobs
s [shell] - start local shell
r [node [shell]] - start remote shell
q - quit erlang
? | h - this message
This hotkey is used to achieve low-level CLI of Erlang shell.
After Ctrl-G
has been pressed, you'll receive invitation like this:
User switch command
--> h
c [nn] - connect to job
i [nn] - interrupt job
k [nn] - kill job
j - list all jobs
s [shell] - start local shell
r [node [shell]] - start remote shell
q - quit erlang
? | h - this message
Let's try to start and connect to just another shell:
--> s shell
--> j
1 {shell,start,[init]}
2 {shell,start,[]}
--> c 2
Eshell V6.4 (abort with ^G)
1>
And this is not all. You can easily connect to remote node in same Erlang cluster. Take a look:
user@node1> erl -sname node1 -setcookie secretcookie
user@node2> erl -sname node2 -setcookie secretcookie
Now on node1
press Ctrl-G
and enter following:
--> r 'node2@localhost'
--> j
1 {shell,start,[init]}
2 {'node2@localhost',shell,start,[]}
--> c 2
(node2@localhost)1> node().
'node2@localhost'
Now press Ctrl-G again!
--> c 1
1> node().
'node1@localhost'
class: center,middle
For first time it will be enough to be able to compile and run just single Erlang files, not applications.
Open your favourite Vim (sorry, bad joke) and create file hello_world.erl
-module(hello_world).
-export([hello/0]).
hello() ->
io:format("Hello world!~n").
Now launch Erlang shell and enter:
1>c(hello_world).
{ok, hello_world}
2>hello_world:hello().
Hello world!
ok
Congratulations! You have compiled your first program on Erlang. Now you can reuse it having only BEAM file.
class: center,middle
erl
is a standard shell. Of course, it's for hardcore lovers. If you need something colorful and tasty - you can use kjell
(*nix-based systems only, sorry, Windows guys).
Kjell looks like this:
Unfortunately, it needs Powerline fonts to work properly.
class: center,middle
class: center,middle