For no apparent reason obvious to myself, I’ve decided to start learning Erlang.

I was reading this article by Curtis Poe about his interpretation of Alan Kay’s criticism of OOP. Maybe that somehow led me down this road, but I don’t really care. Let’s learn Erlang!

Erlang, according to wikipedia is general-purpose, concurrent, functional, and garbage-collected. I’m mostly interested in the concurrent and functional parts of that, and I find the latter more interesting than the former.

I’ve started with the Getting Started with Erlang User’s Guide, and I’ve resolved to get through at least one chapter every 1–2 days. I’ll record my general thoughts on each chapter as I go.

Chapter 1: Sequential Programming

This chapter is pretty much just an introduction to Erlang’s syntax and basic module structure, and some basic REPL-like interactions:

$ erl
Erlang/OTP 21 [erts-10.3.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V10.3.1 (abort with ^G)
1>

In case you wanted to know all my environmental details, I guess. I can say, though, that I am “hipe” to get started.

First module (file tut.erl):

-module(tut).
-export([double/1]).

double(X) ->
    2 * X.

My first thought was that I really like the period as a terminator. It makes a lot of sense to me. Regardless, that’s a pretty minor point. It will probably take some getting used to that variables/parameters start with a capital letter and atoms start with lower-case, but I think it’s a more elegant way to distinguish them than using some more-or-less randomly-selected character.

Meanwhile, back in the Eshell:

1> c(tut).
{ok, tut}
2> tut:double(2).
4

It looks like modules can be hotloaded into the shell using c(<module name>). This is really cool, as it makes it super easy to immediately incorporate and check out changes to your modules.

Most of the rest of Chapter 1 is pretty basic. It introduces a few data types (atoms, tuples, lists, maps, yawn), the io module, how to access standard module man pages, matching and guards, if/case statements and a couple of useful builtins.

One goofy thing I noticed is that Eshell chimes my terminal bell if I type type wrong kind of closing brace. Cute.

The Chapter closes by talking a little bit about higher-order functions (namely lists:map, lists:foreach, and lists:sort), the syntax for which looks like:

lists:map(fun, [])

Where fun is a function with a signature matching the possible elements of the list.

And that’s the end of that Chapter! Next one is Concurrent Programming, a topic that I’m pretty excited to see how Erlang handles.

If you have feedback for me, or want to yell at me or tell me why I’m wasting my time, send me an email.

— M