Skip to content

Commit

Permalink
notes: add graphviz-based images
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrsk committed Oct 12, 2024
1 parent 634a896 commit f0c4b23
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 21 deletions.
8 changes: 4 additions & 4 deletions notes/20240930224229-concurrent_erlang.org
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pid = spawn(ModName, FuncName, [Arg1, Arg2, ..., ArgN]).
sep = 1;

pid1 [label="Pid 1", fontsize="10pt", style=filled, fillcolor=grey];
pid2 [label="Pid 2", xlabel="Mod:Func(Args)", fontsize="10pt", style=filled, fillcolor=red];
pid2 [label="Pid 2", xlabel="Mod:Func(Args)", fontsize="10pt", style=filled, fillcolor=white];

pid1 -> pid2 [label=" Spawn(Mod, Func, Args)", fontsize="10pt", minlen=1, style=dashed];
}
Expand All @@ -46,7 +46,7 @@ Pid = spawn(ModName, FuncName, [Arg1, Arg2, ..., ArgN]).
rankdir="LR";

pid1 [label="Pid 1", xlabel="Pid2 ! { self(), hello }", fontsize="10pt", style=filled, fillcolor=grey];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=red, xlabel="receive (...) end." ];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=white, xlabel="receive (...) end." ];

pid1 -> pid2 [label="{ Pid1, hello }", fontsize="10pt", style=dashed];
}
Expand Down Expand Up @@ -91,7 +91,7 @@ end

pid1 [label="Pid 1", xlabel="Pid 3 ! { foo, ... }", fontsize="10pt", style=filled, fillcolor=grey];
pid2 [label="Pid 2", xlabel="Pid 3 ! { bar, ... }", fontsize="10pt", style=filled, fillcolor=grey];
pid3 [label="Pid 3", fontsize="10pt", style=filled, fillcolor=red];
pid3 [label="Pid 3", fontsize="10pt", style=filled, fillcolor=white];

pid1 -> pid3 [label="{foo, ...}", fontsize="10pt", minlen=1, style=dashed];
pid2 -> pid3 [label="{bar, ...}", fontsize="10pt", minlen=1, style=dashed];
Expand Down Expand Up @@ -144,7 +144,7 @@ end

timeout [label="🕒", fontsize="10pt", style=filled, fillcolor=white];
pid1 [label="Pid 1", fontsize="10pt", style=filled, fillcolor=grey];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=red];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=grey];

timeout -> pid2 [label="Timeout", fontsize="10pt", minlen=1, style=dashed];
pid1 -> pid2 [label="Msg", fontsize="10pt", minlen=1, style=dashed];
Expand Down
24 changes: 22 additions & 2 deletions notes/20241001192402-error_handling_in_erlang.org
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ P3.
rankdir="LR";
sep = 1;

pid1 [label="Pid 1", fontsize="10pt", style=filled, fontcolor=white; fillcolor=black];
pid1 [label="Pid 1", fontsize="10pt", style=filled, fillcolor=red];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=grey];

pid1 -> pid2 [label="{'Exit', Pid1, Reason}", dir=both, fontsize="10pt", minlen=1, style=dashed];
Expand All @@ -80,7 +80,7 @@ P3.
rankdir="LR";
sep = 1;

pid1 [label="Pid 1", fontsize="10pt", style=filled, fontcolor=white; fillcolor=black];
pid1 [label="Pid 1", fontsize="10pt", style=filled, fillcolor=red];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=grey; shape=doublecircle];
pid3 [label="Pid 3", fontsize="10pt", style=filled, fillcolor=grey];

Expand All @@ -93,4 +93,24 @@ P3.
#+RESULTS: erlang-error-trapping
[[file:../static/img/notes/erlang_error_trapping.png]]

#+NAME: erlang-error-propagation
#+BEGIN_SRC dot :file ../static/img/notes/erlang_error_propagation.png :cmdline -Kdot -Tpng :exports results
digraph Trapping {
node [shape=circle];
rankdir="LR";
sep = 1;

pid1 [label="Pid 1", fontsize="10pt", style=filled, fillcolor=red];
pid2 [label="Pid 2", fontsize="10pt", style=filled, fillcolor=grey; shape=doublecircle];
pid3 [label="Pid 3", fontsize="10pt", style=filled, fillcolor=grey];


pid1 -> pid2 [label="{'Exit', Pid1, Reason}", dir=both, fontsize="10pt", minlen=1, style=dashed];
pid2 -> pid3 [dir=both, fontsize="10pt", minlen=2, style=dashed];
}
#+END_SRC

#+RESULTS: erlang-error-propagation
[[file:../static/img/notes/erlang_error_propagation.png]]

#+print_bibliography:
20 changes: 19 additions & 1 deletion notes/20241004123538-erlang_shell.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Some features of the [[id:de7d0e94-618f-4982-b3e5-8806d88cad5d][Erlang]] shell.

* Examples
* Basics
** Compiling and Running "Hello World" in the Shell
#+BEGIN_SRC erlang
-module(hello).
Expand Down Expand Up @@ -64,4 +64,22 @@ terminates the Erlang session. [cite:@armstrong2013 p.14]
> f().
#+END_SRC

* Modifying the Development Environment

You can find the value of the current load path by starting an Erlang shell
and giving the command ~code:get_path()~. The two most common functions that we
use to manipulate the load path are as follows:

#+begin_src erlang
% Add a new directory to the start of the load path.
-spec code:add_patha(Dir) => true | {error, bad_directory}
% Add a new directory to the end of the load path.
-spec code:add_pathz(Dir) => true | {error, bad_directory}
#+end_src

Alternatively, you can start Erlang with a command like this:
#+begin_src shell
$ erl -pa Dir1 -pa Dir2 ... -pz DirK1 -pz DirK2
#+end_src

#+print_bibliography:
31 changes: 29 additions & 2 deletions notes/20241009092203-dializer.org
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,44 @@ Tuple :: tuple() | {T1, T2, ... Tn}
#+END_SRC

New types can be defined with the following syntax:
#+begin_src
#+begin_src erlang
-type NewTypeName(TVar1, TVar2, ... , TVarN) :: Type.
#+end_src

** Specifying the Input and Output Types of a Function

#+BEGIN_SRC
#+BEGIN_SRC erlang
-spec file:open(FileName, Modes) -> {ok, Handle} | {error, Why} when
FileName :: string(),
Modes :: [Mode],
Mode :: read | write | ...
Handle :: file_handle(),
Why :: error_term().
#+END_SRC

** Exporting Types
A module can export some types to declare that other modules are allowed to
refer to them as remote types. This declaration has the following form:

#+BEGIN_SRC erlang
-export_type([T1/A1, ..., Tk/Ak]).
#+END_SRC

** Opaque Types
The main use case for opacity in Erlang is to hide the implementation of a data
type, enabling evolving the API while minimizing the risk of breaking consumers.

* Running Dializer
** Things that confuse Dializer
The dialyzer can get easily confused. We can help prevent this by following a
few simple rules. [cite:@armstrong2013 p.151].
+ Avoid using ~-compile(export_all)~.
+ Provide detailed type specifications for all the arguments to the *exported*
functions in the module.
+ Provide default arguments to all elements in a record definition. If you don't
provide a default, the atom ~undefined~ is taken as the default.
+ Using anonymous variables in arguments to a function often results in types
that are far less specific than you had intended; try to constrain variables
as much as possible.

#+print_bibliography:
4 changes: 2 additions & 2 deletions static/img/notes/erlang_error_exit_signals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions static/img/notes/erlang_error_propagation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/img/notes/erlang_error_trapping.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/img/notes/erlang_selective.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/img/notes/erlang_send.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/img/notes/erlang_spawn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/img/notes/erlang_timeout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0c4b23

Please sign in to comment.