eric | May 1, 2019, 3:59 p.m.
Comments to the book "Learn You Some Erlang For Great Good" by Fred Hébert, Chapter 1 - Starting Out. Challenges: Remembering relevant shell commands and understanding immutability. Important learning goals: Getting to know the shell and understanding the basic syntax.
This article series has come about as a result of my efforts to learn Erlang. In order to learn the language, I am reading the book "Learn You Some Erlang For Great Good" by Fred Hébert. Every time I come across something that I find difficult to understand I will make an effort to understand it and explain my understanding in detail. I will also - as far as possible - site alternative sources, possible exercises and more. First off, maybe you could be a pal and buy Fred Herbert's book. There is a huge effort behind that book and I think Fred deserve our support. You can get it at No Starch Press.
I must admit that I am cheating a bit, because I read ahead quite a few chapters before rereading an earlier chapter and then commenting on that chapter on this site. This is to discover what is important to remember and / or easy to forget as I dig deeper into the content.
Each article has a list of references that I stongly suggest you have a look at, including the Erlang Language Reference, the ETS reference and Joe Armostrong's book Programming Erlang.
If you are not used to Emacs, the shell might take some time getting used to, but it's no big deal. The most important commands are:
help-command in the Erlang shell
The Erlang shell in interrupted state with Ctrl-G
This section is fairly straight-forward as it is mostly about syntax. The points that I find hardest to get - or to remember - are some of the things that sets Erlang syntax apart from all languages I have learned previously.
after and andalso band begin bnot bor bsl bsr bxor case catch cond div end fun if let not of or orelse query receive rem try when xor
This is a bit of a challenge. Coming from other - especially non-functional languages - and being told that
0 == false evaluates to false, and
1 < false evaluates to true
is a bit annoying. Things to keep in mind:
number < atom < reference < fun < port < pid < tuple < list < bit string
So in example (1) above, we are testing the equality between the number 0 with the atom false, which is quite clearly false. In example (2), we are testing whether number 1 is less than the atom false. As atoms are higher up the hierarchy of values than numbers, this turns out to be true.
A tuple is a finite list of elements. It is used to order elements when you know beforehand how many elements there are. Elements can be of any type. You will se a lot of tuples in Erlang. They are used all over the place, in particular in pattern matching expressions.The underscore wildcard is used when you do not care about the value that is being replaced by the wildcard.
What got me a bit confused the first time I tried to use a list is the fact that Erlang will print numbers as letters, unless one of the numbers cannot be represented as a letter. Fortunately, it is possible to print numbers as numbers with io:format (more on that in a bit). Another thing to remember is that a list created with the cons operator ( | ), for instance [ 1 | 2] , gives us a so-called "improper list" that cannot be used with standard list functions.
First off, the Erlang list comprehensions might seem complicated. They aren't.
[3+N | N <- [1,2,3,4]]
just means "make a list from the list 1,2,3,4 and add 3 to each element in the list".
Adding a filter that sorts through the list we are using to construct a new list is also easy:
[3+N | N <- [1,2,3,4], N rem 2 =:=0]
which means "make a list from elements in the list 1,2,3,4 that are dividable by 2, and add 3 to each element in the list".
Erldocs - An alternative to the official sites.
Erlang Patterns - A collection of Erlang patterns
Rebar3 - A build tool for Erlang that makes it easy to compile and test Erlang applications and releases.
Erlang mailing lists and forums
The Google group Erlang Programming
Erlang on Stack Exchange
Erlang on Freenode - Use #Erlang
Erlang on Slack
"Learn You Some Erlang For Great Good", by Fred Hebert
"Programming Erlang", by Joe Armstrong
The Zen of Erlang, by Fred Hebert. A partly practical, partly philosophical take on Erlang.
Ericsson's coding standard for Erlang - Programming rules and conventions.
Getting started with Erlang using IntelliJ IDEA (including Rebar3).
Experienced dev and PM. Data science, DataOps, Python and R. DevOps, Linux, clean code and agile. 10+ years working remotely. Polyglot. Startup experience.